find all data in dynamodb lambda code example
Example: find all data in dynamodb lambda
const AWS = require('aws-sdk')
const dynamoDB = new AWS.DynamoDB({ region: 'ap-south-1', apiVersion: '2019.11. 21' })
var docClient = new AWS.DynamoDB.DocumentClient()
exports.handler = async (event, context, cb) => {
let params = {
TableName: 'TABLE_NAME'
}
let results = await docClient.scan(params).promise()
const response = {
"statusCode": 200,
"success": true,
"message": results.Items,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true
}
};
return cb(null, response)
let params = {
TableName: 'TABLE_NAME',
FilterExpression: "#someKEY = :someKEY_val",
ExpressionAttributeNames: {
"#someKEY": "userId",
},
ExpressionAttributeValues: { ":someKEY_val": "1" }
}
let results = await docClient.scan(params).promise()
const response = {
"statusCode": 200,
"success": true,
"message": results.Items,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true
}
};
return cb(null, response)
}