You need to write a function, which will be executed by AWS Lambda on your behalf.
AWS Lambda is implemented on a container-based model that supports a runtime environment and executes the code as per the Lambda function configuration. When the Lambda function is invoked, it launches the container (an execution environment) based on the AWS Lambda configuration and enables the basic runtime environment, which is required to execute the code.
Let's start with some practical work:
- To create a Lambda function, you must have an AWS account. If you don't have an AWS account, then you need to sign up on AWS (https://aws.amazon.com/) by providing some basic contact and payment information, as it's essential information required by Amazon.
- Go to the Lambda home page (https://console.aws.amazon.com/lambda/home). Click on the Create a function button. This will redirect you to the Create function page, which is described in the next step. Take a look at the following screenshot:
- AWS provides three different options to create a Lambda function, such as Author from scratch, Blueprints, and Serverless Application Repository. We will be using the Blueprint option, which has some built-in Lambda functions. We can choose these blueprints based on our requirements from the search bar, where you can filter by tag and attributes or search by keywords:
- Let's choose a hello-world-python blueprint. Once we choose the blueprint, we need to set up the basic information about the Lambda function. This information includes the Lambda function's Name and Role, as shown in the following screenshot:
- Here, Name will be a unique identification for your Lambda function and Role defines the permissions of your Lambda function.
There are three options available for creating a role:
- Choose an existing role
- Create new role from template(s)
- Create a custom role
Let's look at them in more detail:- Choose an existing role: This allows you to select the previously created role.
- Create new role from template(s): Here, you need to define a role name. AWS Lambda provides ready-made built-in role policy templates that have pre-configured permissions. These are based on other AWS services-related permissions required by the AWS Lambda function. On any role selection, Lambda will automatically add the logging permission to CloudWatch (AWS logging service), as this is the basic permission required by Lambda.
- Create a custom role: AWS provides an additional privilege to create a customized role to access AWS Lambda. Here, you can define the role based on your requirement.
- Let's create the HelloWorld Lambda function with some role. Here, I chose the S3 object read-only permission policy template.
- The following screenshot describes the newly created HelloWorld Lambda function:
The Lambda function includes three sections:
- Configuration
- Triggers
- Monitoring
Let's look at detailed information about the configuration and monitoring. We will have a separate section for triggers.Â