How To Run a Server-less Code On Amazon Web Services
In this tutorial, we will explain the basics of running a code on Amazon Web Services Lambda without provisioning or managing servers. We will guide you how you can create a “Hello World” Lambda function using the Amazon Web Services Lambda console.
Then We will explain how to manually invoke the Lambda function using sample event data and review your output metrics.
1. Under “Compute” services, click on “Lambda” just like the screenshot below.
2. Select “Lambda Blue Print” as it provides an example code to do some minimal processing, and in the AWS console click on “Get started now” and if you already own a Lambda function click on “Create Lambda Function”.
3. Locate “Filter Box” and write on it “hello-world-python” and then select “hello-world-python” blueprint, just like the below screenshot.
4. Now you have to configure your Lambda function the below list explain the configuration method and gives you an example values.
- Name: You can name your lambda function here. For this tutorial, enter hello-world-python.
- Description: You can enter a short description of your function here. This is pre-populated with A starter AWS Lambda Function.
- Runtime: Currently, you can author your Lambda function code in Java, Node.js, or Python 2.7. For this tutorial, leave this on Python 2.7 as the runtime.
Lambda function code:
you can review the example code authored in Python.
Lambda function handler and role:
- Handler: You can specify a handler (a method/function in your code) where AWS Lambda can begin executing your code. AWS Lambda provides event data as input to this handler, which processes the event. In this example, Lambda identifies this from the code sample and this should be pre-populated with lambda_function.lambda_handler.
- Role: Click the drop-down and select Basic Execution Role.
5. Create an “AMI Role” with the required permissions that “Lambda” can invoke the function on it, then click “Allow”.
6. In “Advanced Settings” area, you can configure the memory, timeout, VPC, its recommended to leave it as the default settings and then click Next
7. Review the previous steps, and then click “Create Function”.
8. The console will display the Lambda function, you can test the function by clicking “Test”.
9. Choose “Hello-World” from the sample event list and then click “Save and test”.
10. Upon successful execution, view the results in the console:
– The Execution results section verifies that the execution succeeded.
– The Summary section shows the key information reported in the Log output.
– The Log output section will show the logs generated by the Lambda function execution.