What is AWS Lambda?
AWS Lambda is a cloud computing service offered as a part of the Amazon Web Services. This is an event-driven service, providing serverless processing of codes in response to events such as a message from programs, user action, sensor output, etc. The service automatically manages the resources to provide seamless and real-time processing of requests. AWS Lambda became a part of the Amazon Web Services in the year 2014 and since it has witnessed several developments making the product one of the most sought among AWS services.
The AWS (Amazon Web Services) Lambda is an Amazon product which provides a computing platform, without any server, to run the code (in the languages supported by AWS Lambda) for any type of application or services without any administration.
Basic Working Concept of AWS Lambda
There are 4 basic working steps of Lambda:
- Write or upload code in AWS Lambda.
- Setup your code to trigger from AWS services.
- AWS Lambda runs the code only when triggered.
- Pay for the compute time you use.
How to Use AWS Lambda?
To use AWS Lambda, you need have an AWS account. If you do not have an account, visit the Amazon AWS website (aws.amazon.com) and create an AWS account.
Getting Started with AWS Lambda
A Lambda function can be created either through Lambda console or from the AWS Command Line Interface (CLI) which manages and uses Lambda functions from the command line.
To create a Lambda function through Lambda console, do the following:
- Once you are on the Lambda console, create a function.
- Manually invoke the Lambda function using the sample event data.
The AWS Lambda executes the Lambda function and returns the results.
- Verify the execution results including the logs.
To create a Lambda function through AWS CLI, do the following:
- Install the AWS CLI.
- Use the AWS CLI for all Lambda API actions.
Note: There are some functionalities which are not available in the Lambda console and can only be accessed with the AWS CLI.
AWS Labmda Permissions
Use AWS Identity and Access Management (IAM) to manage access to the Lambda API and other resources like functions and layers. Permissions can be granted to the users and application in your account that uses Lambda or to any other accounts or AWS services that use your Lambda resources.
To grant access to the users in your account that uses Lambda, you can use a permission policy that can be applied to IAM users, groups, or roles.
To grant access to other accounts that use your Lambda resources, you use a policy that applies to the resource itself.
Note: Lambda creates a Node.js function and an execution role that grants the function permission to upload logs.
Hint and Suggestion for using AWS Lambda
Below are some of the hints for effectively using AWS Lambda:
- Use the stateless style in order to write function code
- Avoid declaring function variable outside its scope
- +rx permissions are required on the ZIP files that you upload to ensure that Lambda executes your code.
- If the functions are no longer required, delete it.
Key Features of AWS Lambda
Lambda was developed keeping in mind the growing demand for microservices; where applications are divided into smaller services that are easily scalable, provides a more agile development, amongst other advantages. With the AWS Lambda, developers can deploy one function at the time. Once a function is deployed, Lambda manages all operational aspect of the function such as scaling the service with the increase in requests.
The code running on Lambda is the Lambda function. Once the programmer has created the function, it can be executed. Each function consists of the code and some configuration information. Lambda can launch numerous copies of the function depending on the incoming event requests.
Here, are some of the features of Lambda:
- Add Custom Logic to AWS Service
- Develop Custom back-end Services
- Works with Traditional Codes
- Automated Administration of Infrastructure
- Fault Tolerance
Add Custom Logic to AWS Service
Amazon lambda allows you to implement custom logic to AWS services such as the DynamoDB tables, and S3 buckets making compute seamless across the cloud. It is very easy to get started with the Amazon Lambda. After you have created the function by uploading the code and choosing the memory, IAM, and timeout period, then you can select the resource to trigger function from Kinesis stream, Amazon DynamoDB table, or Amazon S3 bucket. With the change in resources, Lambda will run the function and manage resources to keep up with the incoming requests.
Develop Custom back-end Services
Utilizing the Amazon Lambda, you can develop back-end services for your primary application that can be called-upon requests using the Amazon Lambda or endpoints built with Amazon API gateway.
Works with Traditional Codes
The Amazon Lambda does not require you to learn any new languages, framework, or tools. You can create an application on the Amazon Lambda using traditional languages such as Python, Java, C#, Node.js, and more. As the platform is growing, we can expect Lambda to be compatible with more languages in the future.
Automated Administration of Infrastructure
Lambda manages all the infrastructure aspects of running your code on a fault tolerant, highly available infrastructure allowing you to focus on developing the back-end services to better your application. Lambda eliminates some of the granular level tasks of providing a service over the internet such as the updating of the OS with every new patch release or the scaling of servers to meet the growing requests. Lambda administers everything from security patches, administration, maintenance, to logging-off and monitoring using CloudWatch.
Fault-tolerance is the capability of a computer or a system to continue to operate even when a component fails. The Lambda integrates a built-in fault tolerance mechanism that provides compute even when the code is compromised in a particular region due to system or data center failure. Maintaining compute capability across several Availability zones in a region minimizes the chances of application downtime.
Limitations or Cons of AWS Lambda
- The AWS Lambda allows you to use limited amount of compute and storage resources that can run and store functions. The following limits may vary per-region and can be increased on request.
- Concurrent executions – 1000
- Function and layer storage – 75 GB
Note: In order to request an increase, connect to the support centre console.
- The serverless architecture is best suited for running microservices with short-life span and is not efficient in the case of an application having a long-life.
- The Cold Start in AWS Lambda can prove to be a real hassle delaying the first request in a situation where there has been no request for a long time. This happens as Lambda terminates the function if no request has been recorded in some time.
- CloudWatch is the only tool integrated with AWS Lambda for troubleshooting.
AWS Lambda’s Supported Codes
Since the launch of Amazon Lambda in 2014, the platform has been including new coding languages. Following are some of the languages supported by the platform:
Below are the compatible languages for executing the codes in AWS Lambda:
- Java (Java 8 compatible)
- C# through .NET Core
Using AWS Lambda is so simple that you need to just upload your code and Lambda takes care of everything else. The AWS Lambda executes your code only when it is needed and scales up automatically from few requests per day to thousands per second with High Availability (HA).
Use of AWS Lambda
Following are the uses of AWS Lambda:
- To upload images or objects to Amazon S3
- Provide update to DynamoDBtables
- Respond to website clicks or react to sensor readings from IoT connected devices
- Provision back-end services triggered by custom HTTP requests automatically and “spin down” such services when not in use, to save resource
Advantages of AWS Lambda
The use of AWS Lambda is charged only for the time that the functions were running and hence reduces the operational cost and complexity. Some of the key benefits of using AWS Lambda are:
- The development is fast
- The Operational Management (OM) is easy
- The reduction in operational costs
The AWS Lambda is a very dynamic platform and provides an ease in execution. It is metered in increments of 100 milliseconds and if the usage amount is within the AWS Lambda, the account will not get expired even after 12 months of account signup.