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

Putting an item into the DynamoDB table using the AWS SDK for PHP


Let's understand how to put an item into 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 insert item into DynamoDB table using the AWS SDK for PHP:

  1. Create an instance of the DynamoDB client and initialize it with the specific AWS region and credentials:

    $client = DynamoDbClient::factory(array(
        'profile' => 'default',
        'region' => 'us-east-1'   
    ));
  2. Invoke the putItem method by specifying the details of the item to be put into the DynamoDB table:

    $response = $client->putItem(array(
        'TableName' => 'productTable', 
        'Item' => array(
            'id'       => array('N'      => 30      ), 
            'type'    => array('S'      => 'phone' ),
            'mnfr'     => array('S'      => 'samsung' ),
            'price'    => array('N'      => 44 ),
            'stock'    => array('N'      => 25 ),
          ...