Trouvez toutes les données dans DynamoDB Lambda
//NODE JS
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) => {
//Getting all data
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)
//Query in dynamoDB
let params = {
TableName: 'TABLE_NAME',
FilterExpression: "#someKEY = :someKEY_val", // can use 'AND' 'OR' here
ExpressionAttributeNames: {
"#someKEY": "userId", // its value should be key you want to lookup
},
ExpressionAttributeValues: { ":someKEY_val": "1" } // Value to match
}
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)
}
Lucky Lion