In a TypeScript environment, I am attempting to define a lambda handler.
const sampleFunc = async (event) => {
console.log('request:', JSON.stringify(event, undefined, 2));
return {
statusCode: 200,
headers: { 'Content-Type': 'text/plain' },
body: `Hello, CDK! You've hit ${event.path}\n`,
};
};
exports.handler = sampleFunc(event);
The event parameter is strikethrough due to deprecation, as indicated by the compiler error message:
'event' is deprecated.ts(6385)
lib.dom.d.ts(17314, 5): The declaration was marked as deprecated here.
Interestingly, when the function is defined inline, the code works without any issues.
exports.handler = async function (event) {
console.log('request:', JSON.stringify(event, undefined, 2));
return {
statusCode: 200,
headers: { 'Content-Type': 'text/plain' },
body: `Hello, CDK! You've hit ${event.path}\n`,
};
};