AWS Lambda Services
AWS Lambda (Amazon Web Services Lambda) is a compute service that runs developers’ code in response to events and automatically manages the compute resources for them, making it easy to build applications that respond quickly to new information. It runs the code within milliseconds of trigger. AWS Lambda service is a service where you can upload your code to AWS Lambda and the service can run the code on your behalf using AWS infrastructure. This upload and create is called as AWS Lambda function. It also takes care of provisioning and managing the servers that you use to run the code.
The user needs to supply one of the languages which are supported by AWS Lambda. Currently, AWS Lambda supports Node.js, Python, and Java.
AWS Lambda executes the developers code only when needed and scales automatically. A user can use Lambda for building data processing triggers for AWS services like Amazon S3 and Amazon DynamoDB, or a user can create his own backend which operates at AWS scale, performance, and security.
WHEN SHOULD A USER USE AWS LAMBDA?
AWS Lambda is an optimal compute platform for many applications scenarios, where a user can write the application code in languages supported by AWS Lambda and can run within the AWS Lambda standard runtime environment and resources provided by Lambda.
When using AWS Lambda, a user is only responsible for the code. It manages and balances the memory, CPU, network, and other resources. These constraints enable AWS Lambda to perform operational and administrative activities on users behalf, including provisioning capacity, applying security patches, deploying the code, monitoring and logging to Lambda functions.
HOW AWS LAMBDA WORKS
While building applications in AWS Lambda, the core components are Lambda functions and event sources. An event source is an AWS service or custom application that publishes an event, and a Lambda function is the custom code that processes the events. Below are the following scenarios to be considered.
File Processing: For an instance, you have a photo sharing application. People use your application to upload photos, and the application stores the user photos in Amazon S3 bucket.Then your application creates a thumbnail version of each user photos and displays them on the user’s profile page. In this scenario, you may choose to create a Lambda function that creates a thumbnail automatically. Your Lambda function code can read the photo object from the S3 bucket, create a thumbnail version and can save it in another S3 bucket.
Data and Analytics: If suppose you are building an analytics application and storing raw data in a DynamoDB table, when you write, update, or delete the items in a table, DynamoDB streams can publish item update events to a stream associated with the table. In that case, the event data provides the item key, event name, and other details as needed. A user can write a Lambda function to generate custom metrics by accumulating raw data.
Websites: If you are creating a website and you want to host the backend logic on Lambda. You can invoke your Lambda function over HTTP using Amazon API gateway as the HTTP endpoint. Then your web client can invoke the API gateway to route the request to Lambda.
Mobile Applications: If you have a custom mobile application that produces events. You can create Lambda function to process events published by your custom application.
COMPUTE REQUIREMENTS – LAMBDA FUNCTION CONFIGURATION
A Lambda function consists of code and associated dependencies. A Lambda function also has configuration information associated with it. At the beginning, you specify the configuration information when you create a Lambda function. Lambda provides an API for the user to provide some of the configuration data. Lambda function configuration includes the following elements:
Compute resource that a user needs: A user can specify the amount of memory that he wants to allocate for the Lambda function. AWS Lambda allocates CPU power proportional to the memory by using the same ratio as an Amazon EC2 instance type.
Maximum execution time: The user pays for the AWS resources that are used to run the users Lambda functions. To prevent the Lambda function running indefinitely, a user specifies a timeout. When it reaches the specified timeout the AWS Lambda function terminates the Lambda function.
Execution role: This is the role that AWS Lambda assumes while executing the Lambda function on behalf of a user.
Handler name: The handler refers to the method in the user’s code where AWS Lambda begins execution.