Amazon Web Services - Lambda

AWS Lambda is a responsive cloud service that inspects actions within the application and responds by deploying the user-defined codes, known as functions. It automatically manages the compute resources across multiple availability zones and scales them when new actions are triggered.
AWS Lambda supports the code written in Java, Python and Node.js, and the service can launch processes in languages supported by Amazon Linux (includes Bash, Go & Ruby).
Following are some recommended tips while using AWS Lambda.
  • Write your Lambda function code in a stateless style.
  • Never declare any function variable outside the scope of the handler.
  • Make sure to have a set of +rx permissions on your files in the uploaded ZIP to ensure Lambda can execute code on your behalf.
  • Delete old Lambda functions when no longer required.

How to Configure AWS Lambda?

Follow these steps to configure AWS Lambda for the first time.
Step 1 − Sign in to AWS account.
Step 2 − Select Lambda from AWS services section.
Amazon Web Services
Step 3 − Select a Blueprint (optional) and click the Skip button.
Lambda
Step 4 − Provide the necessary details to create a Lambda function as shown in the following screenshot and paste the Node.js code that will be triggered automatically whenever a new item is added in DynamoDB. Select all the required permissions.
Configure Function
Lambda Function Handler
Step 5 − Click the Next button and verify your details.
Step 6 − Click the Create Function button.
Now, when we select the Lambda service and select the Event Sources tab, there will be no records. Add at least one source to the Lambda function to work. Here, we are adding DynamoDB Table to it.
We have created a table using DynamoDB (we will discuss this in detail in DynamoDB chapter).
Step 7 − Select the stream tab and associate it with the Lambda function.
Amazon DynamoDB
You will see this entry in Event Sources Tab of Lambda Service page.
Step 8 − Add some entries into the table. When the entry gets added and saved, then Lambda service should trigger the function. It can be verified using the Lambda logs.
Step 9 − To view logs, select the Lambda service and click the Monitoring tab. Then click the View Logs in CloudWatch.
Monitoring

Benefits of AWS Lambda

Following are some of the benefits of using Lambda tasks −
  • Lambda tasks need not to be registered like Amazon SWF activity types.
  • We can use any existing Lambda functions that you’ve already defined in workflows.
  • Lambda functions are called directly by Amazon SWF; there is no need design a program to implement and execute them.
  • Lambda provides us the metrics and logs for tracking function executions.

AWS Lambda Limits

Following are the three types of Lambda limits.

Throttle Limit

The throttle limit is 100 concurrent Lambda function executions per account and is applied to the total concurrent executions across all functions within a same region.
The formula to calculate the number of concurrent executions for a function = (average duration of the function execution) X (number of requests or events processed by AWS Lambda).
When throttle limit is reached, then it returns a throttling error having an error code 429. After 15-30 minute you can start work again. The throttle limit can be increased by contacting AWS support center.

Resources Limit

The following table shows the list of resources limits for a Lambda function.
ResourceDefault Limit
Ephemeral disk capacity ("/tmp" space)512 MB
Number of file descriptors1,024
Number of processes and threads (combined total)1,024
Maximum execution duration per request300 seconds
Invoke request body payload size6 MB
Invoke response body payload size6 MB

Service Limit

The following table shows the list of services limits for deploying a Lambda function.
ItemDefault Limit
Lambda function deployment package size (.zip/.jar file)50 MB
Size of code/dependencies that you can zip into a deployment package (uncompressed zip/jar size)250 MB
Total size of all the deployment packages that can be uploaded per region1.5 GB
Number of unique event sources of the Scheduled Event source type per account50
Number of unique Lambda functions you can connect to each Scheduled Event5
For latest updated limit structure & more information, visit − https://docs.aws.amazon.com/lambda/latest/dg/limits.html/

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...