๐Ÿ“Œ๐Ÿ“Œ 10 Features of AWS Lambda๐Ÿ“Œ๐Ÿ“Œ

Prashant Lakhera
5 min readNov 14, 2022

--

๐Ÿ“– To view the complete course https://www.101daysofdevops.com/courses/100-days-of-aws/

โžก๏ธ You can contact me via https://linktr.ee/prashant.lakhera

What is AWS Lambda?

Lambda is a function as a service(FaaS). In simplified terms, you provide code to Lambda, which runs it and only bills you for what you consume.

1. Lambda Supported languages

AWS Lambda supported multiple languages through the use of runtimes.

Reference: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

2. Lambda Versions

With lambda function, itโ€™s possible to define the specific version of lambda functions(think of it like versioning in GitHub). Once you publish the version, itโ€™s immutable that it canโ€™t be changed. The version will get its own Amazon Resource Name(ARN). There is also a concept of $Latest which points to the latest version.

  • Publish the new version
  • Once you published the version, you can view it
  • It create a unique ARN and its immutable
arn:aws:lambda:us-east-1:12345678:function:my-demo-lambda:1

3. Lambda Aliases

You can create aliases that point to a different version(prod, dev, stage). This is not immutable and can be changed. Alias is just a pointer to the function version. Using aliases, you can create blue/green deployment, which means a certain percentage(90%) of the workload can go to alias1 and the other half (10%)goes to alias2. Services can be configured to point to aliases rather than the version for, e.g., API gateway.

4. Environment Variables

Environment variable in Lambda is the combination of key/value pairs. Every Lambda function can have 0 or more environment variable. These variables can be accessed within the execution environment. Environment variable can be encrypted using KMS.

Code to test it

import json
import os

def lambda_handler(event, context):
print (os.environ['ENV'])

Output

Test Event Name
test

Response
null

Function Logs
START RequestId: 73243bf0-6f9b-4e37-bc4d-ab7a3e880188 Version: $LATEST
Dev

5. Lambda Layers

Lambda layer lets you share your code, you can upload the layer once, and then you can reference it for any function. Any layers we create will be extracted inside the /opt inside the execution environment and used the same way the libraries are included in the function zip. One of the most important features of the layer is that it allows us to use custom runtime and then use languages, e.g., Rust, and C++, which are not currently supported by Lambda.

6. Lambda Container Image

Lambda now supports container images. You can now deploy a container to your lambda function. For more info, check this doc https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/

7. Lambda and ALB Integration

The Lambda function can process requests from Application Load Balancer(ALB). Using rules, you can route the HTTP request to the Lambda function, and based on the path and header rule, it processes and return the response to the Lambda function.

https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html

8. Lambda with API gateway

The most popular use case is creating web API with an HTTP endpoint for your Lambda function using an API gateway.

9. Lambda function to access resources in VPC

You can configure the Lambda function to connect to private subnets in a VPC. The use case for this is if you create any resources in your VPC and want your Lambda function to access them, e.g., EC2 instance, RDS DB, etc.

10. Runtime Environment

Your code is loaded and executed within a runtime environment. This runtime environment is specifically created to run a certain language. You also specify the amount of resources that the runtime environment will use. You specify the amount of memory and depending upon the amount of memory, a certain amount of virtual CPU is allocated. To configure the memory for your function, set a value between 128 MB and 10,240 MB in 1-MB increments. At 1,769 MB, a function has the equivalent of one vCPU (one vCPU-second of credits per second). Also, 512MB of disk space is allocated under /tmp but can be scaled up to 10240MB. The Lambda function can run up to 15min(900second). https://aws.amazon.com/lambda/pricing/

Reference: https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html

NOTE: Everytime your Lambda function is executed, a new runtime environment is created with all the components that your Lambda function needs. So for every execution of your Lambda function and a new environment is created, it terminates once the execution is finished. The Lambda function is stateless, that is, no data is left over from a previous invocation.

--

--

Prashant Lakhera
Prashant Lakhera

Written by Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP