Certainly! Below is an example of a simple Lambda function written in Node.js that logs a message:
// Example Node.js Lambda function
exports.handler = async (event) => {
console.log('Hello from Lambda!');
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
Explanation:
- exports.handler: This is the entry point for the Lambda function.
- async (event) => { ... }: This is an asynchronous function that AWS Lambda invokes with an event parameter containing the event data.
- console.log('Hello from Lambda!');: Logs a message to the AWS CloudWatch logs.
- const response = { ... }: Defines a basic HTTP response with a status code and body.
- return response;: Returns the response back to the caller.