Complete the code to import the AWS SDK for DynamoDB in a Lambda function.
const AWS = require('[1]');
The AWS SDK for JavaScript is imported using 'aws-sdk'. This allows access to DynamoDB and other AWS services.
Complete the code to create a DynamoDB DocumentClient instance in the Lambda function.
const docClient = new AWS.[1]();The DocumentClient simplifies working with DynamoDB by abstracting away low-level details. It is created with 'new AWS.DocumentClient()'.
Fix the error in the code to put an item into the DynamoDB table named 'Users'.
const params = { TableName: 'Users', Item: [1] };
await docClient.put(params).promise();The Item must be an object with key-value pairs. Using curly braces { } defines an object. Square brackets or strings are invalid here.
Fill both blanks to get an item from the 'Products' table where the 'productId' equals '123'.
const params = { TableName: '[1]', Key: { [2]: '123' } };
const data = await docClient.get(params).promise();The TableName must be 'Products' and the Key attribute must be 'productId' to match the primary key of the table.
Fill all three blanks to update the 'status' attribute to 'active' for the item with 'userId' 'u123' in the 'Accounts' table.
const params = {
TableName: '[1]',
Key: { [2]: 'u123' },
UpdateExpression: 'set [3] = :s',
ExpressionAttributeValues: { ':s': 'active' }
};
await docClient.update(params).promise();The TableName is 'Accounts', the Key attribute is 'userId', and the attribute to update is 'status'.