How to do it...

Let's have a look at the following steps:

  1. The first thing to do is log in to the Lambda console (https://console.aws.amazon.com/console/home). Then, you need to locate and select Lambda under compute in order to open the AWS Lambda console (which is highlighted in green in the following screenshot):

AWS: Selecting a Lambda service
  1. Then, in the AWS Lambda console, select Get Started Now and then create a Lambda function:

AWS: Lambda start page
  1. In the filter box, type hello-world-python and select the hello-world-python blueprint.
  2. Now we need to configure the Lambda function. The following list shows the configurations and provides example values:
  • Configure function:
  • Name: Enter the name of the function here. For this tutorial, enter hello-world-python.
  • Description: Here, you can enter a brief description of the function. This box is pre-filled with the phrase A starter AWS Lambda Function.
  • Runtime: At the moment, it is possible to write the code of the Lambda function in Java, Node.js, and Python 2.7, 3.6, and 3.7. For this tutorial, set up Python 2.7 as a runtime.
  • Lambda function code:
  • As you can see in the following screenshot, it is possible to review the Python sample code.
  • Lambda function handler and role:
  • Handler: You can specify a method in which AWS Lambda can start executing the code. AWS Lambda provides event data as input to the handler, which will process the events. In this example, Lambda identifies the event from the example code, so the field will be compiled with lambda_function.lambda_handler.
  • Role: Click on the drop-down menu and select Basic Execution Role:

AWS Configure function page
  1. At this point, it is necessary to create a role for execution (named IAM Role) with the necessary authorizations to be interpreted by AWS Lambda as the executor of the Lambda function. By clicking Allow, the Configure function page will be returned, and the lambda_basic_execution function will be selected:

AWS: Role summary page
  1. The console saves the code in a compressed file, which represents the distribution package. The console then loads the distribution package into AWS Lambda to create the Lambda function:

AWS: Lambda review page

It is now possible to test the functions, check the results, and display the logs:

  1. To run our first Lambda function, click on Test:

AWS: Lambda testing page
  1. Enter an event in the pop-up editor to test the function.
  2. Select Hello World from the Sample event template list on the Input test event page:

AWS: Lambda template

Click Save and test. Then, AWS Lambda will perform the function on your behalf.

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

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