2019-01-22 20:27:36 +00:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2018-10-11 14:17:57 -07:00
// ABOUT THIS NODE.JS SAMPLE: This sample is part of the SDK for JavaScript Developer Guide topic at
// https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/dynamodb-example-table-read-write-batch.html
2019-01-22 20:27:36 +00:00
// snippet-start:[dynamodb.JavaScript.batch.GetItem]
2018-10-11 14:17:57 -07:00
// Load the AWS SDK for Node.js
var AWS = require ( "aws-sdk" ) ;
// Set the region
AWS . config . update ( { region : "REGION" } ) ;
// Create DynamoDB service object
var ddb = new AWS . DynamoDB ( { apiVersion : "2012-08-10" } ) ;
var params = {
RequestItems : {
TABLE _NAME : {
Keys : [
2019-01-22 20:27:36 +00:00
{ KEY _NAME : { N : "KEY_VALUE_1" } } ,
{ KEY _NAME : { N : "KEY_VALUE_2" } } ,
{ KEY _NAME : { N : "KEY_VALUE_3" } } ,
2018-10-11 14:17:57 -07:00
] ,
2019-01-22 20:27:36 +00:00
ProjectionExpression : "KEY_NAME, ATTRIBUTE" ,
2018-10-11 14:17:57 -07:00
} ,
} ,
} ;
ddb . batchGetItem ( params , function ( err , data ) {
if ( err ) {
console . log ( "Error" , err ) ;
} else {
data . Responses . TABLE _NAME . forEach ( function ( element , index , array ) {
console . log ( element ) ;
} ) ;
}
} ) ;
2019-01-22 20:27:36 +00:00
// snippet-end:[dynamodb.JavaScript.batch.GetItem]