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

Getting multiple items using the AWS SDK for PHP


Let's understand how to get multiple items from 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 try to understand how to get multiple stored items from the DynamoDB table using PHP:

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

    $client = DynamoDbClient::factory(array(
        'profile' => 'default',
        'region' => 'us-east-1' 
    ));
  2. Create the batchGetItem request and provide the primary keys of items to be fetched:

    $response = $client->batchGetItem(array(
        "RequestItems" => array(
            "Reply" => array(
                "Keys" => array(
                    array( 
                        "id"  => array( 'N' => "10"),
                        "type" => array( 'S' => "phone"),
                    ),
                    array( 
                        "id"  => array( 'S' => "20"),
            ...