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 DynamoDB table with a Local Secondary Index using the AWS SDK for PHP


Now, let's see how to create a DynamoDB table with a Local Secondary Index using the AWS SDK for PHP.

Getting ready

To perform this operation, you can use the IDE of your choice.

How to do it…

In the earlier chapters, we have seen how to create a DynamoDB table. Now we are going to see how to create a DynamoDB table using a Local Secondary Index:

  1. Instantiate the DynamoDB client for PHP. Specify the AWS region in which you would wish to create the table:

    $client = DynamoDbClient::factory(array(
        'profile' => 'default',
        'region' => 'us-west-1'  
    ));
  2. Now, we have to initialize the createtable request specifying the AttributesDefinition, KeySchema, and LocalSecondaryIndex specifications. Here, we will use id and type as the table hash and range keys, respectively, while id and mnfr will be used as hash and range keys for the local secondary index:

    $result = $client->createTable(array(
        'TableName' =&gt...