Creating the AWS Lambda function

In this section, we will create the AWS Lambda function by using Python. We will build the AWS Lambda function graphically through a browser. To complete this task, you should have an active AWS account:

  1. Firstly, open a browser and navigate to http://console.aws.amazon.com/lambda. Our scenario is to build the echo function. It will send back any message from the caller. The message format is JSON.
  2. On the AWS Lambda function dashboard, you can create a new Lambda function by clicking on the Create function button. Then, fill in the function name and its role, as shown in the following screenshot. When done, click on the Create function button. For instance, my Lambda function name is echo-lambda:
  1. If successful, you will see a code editor for the AWS Lambda function. Select Edit code inline from the code entry type. Set Python 2.7 for the runtime and lambda_function.lambda_handler for the Handler field. You can see this entry in the following screenshot:
  1. The following is our Python code for the AWS Lambda function. We return a message with the attribute msg from the caller as a JSON message:
def lambda_handler(event, context):
data = event['msg']
return { 'msg': data }

Save these scripts when you are done. 

We have created the AWS Lambda. We will test it in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.232.187