Lambda Hello World (Node.js)
Create the Hello World function (Node.js)
- Open Lambda console -> Create function -> Author from scratch.
- Name:
hello-node, Runtime: Node.js 18.x, Role: AWSLambdaBasicExecutionRole.
- Paste the sample handler:
exports.handler = async (event) => {
const name =
(event?.queryStringParameters || {}).name ||
event?.name ||
"world";
return {
statusCode: 200,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: `Hello, ${name}` })
};
};
- Save.
Test in the console
- Click Test -> create a new event, body:
{"name":"Alice"}.
- Run Test and check the response
Hello, Alice.
- Open Monitor -> Logs to view the CloudWatch log stream.
Basic configuration
- Memory/Timeout: increase/decrease as needed (e.g., 128–256 MB, 3–10s).
- Log retention: open CloudWatch Log group
/aws/lambda/hello-node -> Edit retention (7–14 days).
- If
name is missing, you can return 400 with a clear message (optional).