Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am triggering my lambda function from an api. The lambda function returns a query from a dynamoDB table, I am passing an ID to in api. but it returns an error. "Cannot destructure property 'Id' of 'event.pathParameters' as it is undefined".

'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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...