Now let's see how to create a DynamoDB table with a Global Secondary Index using the AWS SDK for PHP.
In the earlier chapters, we have seen how to create a DynamoDB table. Now, we are going to see how to create a DynamoDB table using a Global Secondary Index:
Instantiate the
DynamoDB
client for PHP. Specify the AWS region in which you wish to create the table:$client = DynamoDbClient::factory(array( 'profile' => 'default', 'region' => 'us-west-1' ));
Now we have to initialize the create table request, specifying the
AttributesDefinition
,KeySchema
, andGlobalSecondaryIndex
specifications. Here, we will useid
andtype
as the table hash and range keys, respectively, whilename
andmnfr
will be used as the hash and range keys for the global secondary index:$tableName = "productTable"; $result = $client->createTable...