Complete the code to initialize the DynamoDB client using the AWS SDK.
const AWS = require('aws-sdk'); const dynamoDB = new AWS.DynamoDB({ region: [1] });
The region is required to tell the SDK where your DynamoDB service is located.
Complete the code to put an item into a DynamoDB table using the SDK.
const params = {
TableName: 'Users',
Item: {
'UserId': { S: '123' },
'Name': { S: [1] }
}
};
dynamoDB.putItem(params, (err, data) => { /* callback */ });The 'Name' attribute expects a string value wrapped in quotes.
Fix the error in the code to correctly get an item from DynamoDB using the SDK.
const params = {
TableName: 'Users',
Key: {
'UserId': { [1]: '123' }
}
};
dynamoDB.getItem(params, (err, data) => { /* callback */ });The key attribute type for a string is 'S' in DynamoDB SDK.
Fill both blanks to update an item attribute using the DynamoDB SDK.
const params = {
TableName: 'Users',
Key: { 'UserId': { [1]: '123' } },
UpdateExpression: 'set #N = :name',
ExpressionAttributeNames: { '#N': [2] },
ExpressionAttributeValues: { ':name': { S: 'Bob' } }
};
dynamoDB.updateItem(params, (err, data) => { /* callback */ });The key type for UserId is 'S' for string, and the attribute name to update is 'Name'.
Fill all three blanks to query items from DynamoDB with a condition using the SDK.
const params = {
TableName: 'Orders',
KeyConditionExpression: '#id = :orderId',
ExpressionAttributeNames: { [1]: 'OrderId' },
ExpressionAttributeValues: { [2]: { S: 'A123' } },
ProjectionExpression: [3]
};
dynamoDB.query(params, (err, data) => { /* callback */ });ExpressionAttributeNames maps '#id' to 'OrderId', ExpressionAttributeValues uses ':orderId', and ProjectionExpression lists attributes to return.