I'm brand new to NodeJS and I recently updated the runtime of my AWS Lambda functions from 8.10 to 14. I've ensured all deprecated code has been udpated. I'm not trying to fully deploy my Lambdas. When testing in the AWS Lambda console, I get the following error:
{
"errorType": "TypeError",
"errorMessage": "Cannot read property 'id' of undefined",
"trace": [
"TypeError: Cannot read property 'id' of undefined",
" at Runtime.exports.handler (/var/task/index.js:11:69)",
" at processTicksAndRejections (internal/process/task_queues.js:95:5)"
]
}
Here's some of the code used in the Lambda function (emitting a function that is irrelevant to the issue):
exports.handler = async(event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
console.log(event);
let body = await createJSONBody(event);
let res = await makeHTTPPost(body);
response.statusCode = 200,
response.body = `Created Ticket Number: ${JSON.parse(res).ticket.id}`
return response;
};
function createJSONBody(event) {
return new Promise((resolve, reject) => {
let requesterID = event.requester_id ? event.requester_id : 1234567890;
let subject = event.subject;
let priority = event.priority;
let commentBody = event.comment_body;
let pkc = event.pkc;
console.log(pkc)
let ticket = {
"ticket": {
priority: priority,
requester_id: requesterID,
subject: subject,
tags: ['from_aws'],
custom_fields: [{
"id": 12345,
"value": pkc
}],
comment: {
body: commentBody,
"public": false
}
}
};
resolve(ticket);
});
}
What I've tried so far:
- TypeError: Cannot read property 'id' of undefined - AWS Lambda
- Serverless : "errorMessage": "Cannot read property 'id' of undefined",
Does anyone have an idea about what's going on? I really appreciate any and all help. Thank you.