Installation guide

'region' => '<region name>',
'version' => '2011-12-05'
));
You can provide your access keys like in the preceding example, or you can choose to omit them if you are using
AWS Identity and Access Management (IAM) roles for EC2 instances or credentials sourced from the
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
Service builder
A more robust way to connect to Amazon DynamoDB is through the service builder. This allows you to specify
credentials and other configuration settings in a configuration file. These settings can then be shared across all
clients so that you only have to specify your settings once.
use Aws\Common\Aws;
// Create a service builder using a configuration file
$aws = Aws::factory('/path/to/my_config.json');
// Get the client from the builder by namespace
$client = $aws->get('DynamoDb');
Creating tables
You must first create a table that can be used to store items. Even though Amazon DynamoDB tables do not use a
fixed schema, you do need to create a schema for the table's keys. This is explained in greater detail in Amazon
DynamoDB's Data Model documentation. You will also need to specify the amount of provisioned throughput that
should be made available to the table.
// Create an "errors" table
$client->createTable(array(
'TableName' => 'errors',
'KeySchema' => array(
'HashKeyElement' => array(
'AttributeName' => 'id',
'AttributeType' => 'N'
),
'RangeKeyElement' => array(
'AttributeName' => 'time',
'AttributeType' => 'N'
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 20
)
));
The table will now have a status of CREATING while the table is being provisioned. You can use a waiter to poll the
table until it becomes ACTIVE.
// Wait until the table is created and active
$client->waitUntilTableExists(array(
'TableName' => 'errors'
));
A full list of the parameters available to the createTable() operation can be found in the API documentation.
Updating a table
You can also update the table after it's been created using the updateTable() method. This allows you to do things
like increase or decrease your provisioned throughput capacity.
Amazon DynamoDB (2011-12-05)
74