Lambda
Creating a Lambda Function
- Open the AWS Management Console and sign in to your AWS account.
- Navigate to the Lambda service by clicking on the "Services" tab and selecting "Lambda".
- In the Lambda console, click on the "Create function" button.
- Select "Author from scratch".
- In the "Basic information" pane, for "Function name" enter
myLambdaFunction
. - For "Runtime" choose "Node.js 20.x".
- For "Execution role" choose "New from scratch".
- In the "Permissions" pane, select the "AWS Lambda basic execution role" policy and click on "Choose".
- Click on "Create function".
- In the "Function code" pane, paste the following code:
JavaScript
exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify('Hello, World!')
};
};
- Click on "Save".
- In the "Tester" pane, click on "Test".
- The results of the test will be displayed in the "Execution result" pane.
Publish Lambda
- Once tested and validated, you need to obtain an url to trigger this from anywhere
- Goto "Configuration" tab and select "Function URL"
- Click "Create Function URL"
- Select NONE to allow anyone with the link to access this function
- Click on the function URL and you will see the output of the function in browser
Hello, World!