Creating a table using the AWS SDK for PHP
Now, let's understand how to create a DynamoDB table using the AWS SDK for PHP.
Getting ready…
You can use the IDE of your choice to code these recipes.
How to do it…
Let's start with creating a table called productTablePHP
:
Instantiate the DynamoDB client for PHP. Specify the AWS region in which you wish to create the table in:
$client = DynamoDbClient::factory(array( 'profile' => 'default', 'region' => 'us-west-1' ));
Invoke the
createTable
method by specifying the details, such as the table name, hash and range keys, and provisioned capacity units. Here, we will create a table with the primary key as the composite hash and range keys:$result = $client->createTable(array( 'TableName' => $tableName, 'AttributeDefinitions' => array( array( 'AttributeName' => 'id', 'AttributeType' => 'N' ), array( 'AttributeName' => 'type', 'AttributeType' ...