我正在从 api 触发我的 lambda 函数。lambda 函数从 dynamoDB 表返回一个查询,我将一个 ID 传递给 api。但它返回一个错误。“无法解构‘event.pathParameters’的属性‘Id’,因为它是未定义的”。
'use strict'
const AWS = require('aws-sdk');
AWS.config.update({ region: "ap-south-1"})
exports.handler = async (event, context)=> {
const ddb = new AWS.DynamoDB({apiVerion: "2012-10-08"});
const documentClient = new AWS.DynamoDB.DocumentClient({ region: "ap-south-1"})
let responseBody = ""
let statusCode=""
const { Id } =event.pathParameters;// to get the id from api
const params = {
TableName: "User",
Key:{
// Id: "1"
Id: Id
}
}
try{
const data = await documentClient.get(params).promise();
// console.log(data);
let x = data.Iteml
responseBody = JSON.stringify
statusCode = 200
}
catch(err){
// console.log(err);
responseBody = " Unable to get User data"
statusCode= 403;
}
const response={
statusCode: statusCode,
headers:{
"myheader":"test"
},
body: responseBody
}
return response;
}