Book Image

DynamoDB Cookbook

By : Tanmay Deshpande
Book Image

DynamoDB Cookbook

By: Tanmay Deshpande

Overview of this book

Table of Contents (18 chapters)
DynamoDB Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. 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'  
    ));
  2. 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' ...