Querying a Global Secondary Index using the AWS SDK for PHP
Now, we are going to see how to query a global secondary index using the AWS SDK for PHP.
Getting ready
To perform this operation, you can use the IDE of your choice. To perform a query operation, you should first add items using the AWS Console or SDK, as we have seen in the earlier chapters.
How to do it…
The Query API on a Global Secondary Index is similar to the query API on a DynamoDB table. Perform the following operations in order to query the 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' ));
Invoke the query method from the
DynamoDB
client by specifying the secondary index keys on which you wish to perform the query. Here, we want to fetch all the products whosename
isS3
:$tableName = 'product'; $response = $client->query(array( 'TableName' => $tableName...