Getting an item from the DynamoDB table using the AWS SDK for PHP
Let's understand how to get an item from the DynamoDB table using the AWS SDK for PHP.
Getting ready
To perform this operation, you can use the IDE of your choice.
How to do it…
Let's try to understand how to retrieve a stored item from the DynamoDB table using PHP:
Create an instance of the
DynamoDB
client and initialize it with the AWS region and credentials:$client = DynamoDbClient::factory(array( 'profile' => 'default', 'region' => 'us-east-1' ));
Call the
getItem
method by specifying theprimary
key used for the table:$response = $client->getItem(array( 'TableName' => 'productTable', 'Key' => array( 'id' => array( 'N' => 30 ),'type' => array( 'S' => 'phone' ) ) ));
You can
print
the response if required:print_r ($response['Item']);
How it works…
The API invocations call the DynamoDB services and get the item from the specified table.