Complete the code to create a DynamoDB DocumentClient instance.
const AWS = require('aws-sdk'); const docClient = new AWS.DynamoDB.[1]();
The DocumentClient is the abstraction layer for DynamoDB that simplifies working with items as JSON.
Complete the code to put an item into a DynamoDB table using DocumentClient.
const params = {
TableName: 'Users',
Item: { id: '123', name: 'Alice' }
};
docClient.[1](params).promise();The put method inserts or replaces an item in the table.
Fix the error in the code to get an item by key using DocumentClient.
const params = {
TableName: 'Products',
Key: { productId: 'abc123' }
};
docClient.[1](params).promise();The get method retrieves a single item by its key.
Fill both blanks to update an item attribute using DocumentClient.
const params = {
TableName: 'Orders',
Key: { orderId: '789' },
UpdateExpression: 'set [1] = :val',
ExpressionAttributeValues: { ':val': [2] }
};
docClient.update(params).promise();The UpdateExpression sets the attribute named in the first blank to the value in the second blank.
Here, we update the status attribute to the string 'delivered'.
Fill all three blanks to query items with a condition using DocumentClient.
const params = {
TableName: 'Employees',
KeyConditionExpression: '[1] = :id',
ExpressionAttributeNames: { '#name': '[2]' },
ExpressionAttributeValues: { ':id': [3] }
};
docClient.query(params).promise();The KeyConditionExpression uses the partition key attribute name in the first blank.
The ExpressionAttributeNames maps the placeholder #name to the actual attribute name in the second blank.
The ExpressionAttributeValues provides the value for the key in the third blank.