AWS Lambda
AWS Lambda is an event-driven computing cloud service from Amazon Web Services that allows developers to program functions on a pay-per-use basis without having to provision storage or compute resources to support them. This is sometimes referred to function-as-a-service (FaaS).
AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services. Therefore you don’t need to worry about which AWS resources to launch, or how will you manage them. Instead, you need to put the code on Lambda, and it runs.
In AWS Lambda the code is executed based on the response of events in AWS services such as add/delete files in S3 bucket, HTTP request from Amazon API gateway, etc. However, Amazon Lambda can only be used to execute background tasks.
Types of services
AWS offers thousands of discrete services — nearly 2,000 were released in 2018 alone. AWS uses the AWS Lambda console to help users monitor and manage their Lambda applications. The menu includes stacks that you launch in AWSCloudFormation by using the AWS CloudFormation console, the AWS Serverless Application Repository, the AWS CLI, or the AWS SAM CLI.
AWS Lambda functions
A function is a small piece of programming that carries out a specific task. Developers use AWS Lambda to code and run functions in response to specific events in other Amazon cloud services, such as the creation of an object in an Amazon Simple Storage Service (S3) bucket. Each Lambda function runs in an isolated computing environment with its own resources and view of the file system.
When AWS Lambda functions are called, the storage and compute resources for that function spin up automatically as a metered service.
AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume — there is no charge when your code is not running.
With Lambda, you can run code for virtually any type of application or backend service. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app.
What can you build with AWS Lambda?
Examples:
- Web applications: By combining AWS Lambda with other AWS services, developers can build web applications that scale up and down and run in multiple data centers.
- Mobile backends: You can build backends using AWS Lambda and Amazon API Gateway for the authentication and execution of API requests. For example, Bustle runs a serverless backend for its Bustle iOS app and websites using AWS Lambda and Amazon API Gateway.
- IoT backends: You can build serverless backends using AWS Lambda to handle web, mobile, Internet of Things (IoT), and 3rd party API requests.
How developers use AWS Lambda
Developers can list, delete, update and monitor functions through the Lambda dashboard, command-line interface (CLI) or software development kit (SDK). The service also performs infrastructure-focused activities, such as server and operating system maintenance, patch deployment and logging through AWS CloudWatch. Lambda also supports third-party logging application programming interfaces (APIs), and developers can connect custom APIs endpoints to Lambda through the Amazon API Gateway service.
AWS Lambda pricing and free tier
Amazon bills users based on the number of requests served and the compute time needed to run the code, metered in increments of 100 milliseconds. If a function is never called, it costs the developer nothing.
AWS Lambda is available with a free tier of service that includes one million free requests and 400,000 gigabyte-seconds of compute time per month. Amazon charges users for each additional million requests. Additional charges may incur within associated AWS products.
Events that Trigger AWS Lambda
Here, are Events which will be triggered when you use AWS Lambda.
- Insert, updating and deleting data Dynamo DB table
- To include push notifications in SNS
- To search for log history in CloudTrail
- Entry into an S3 object
- DynamoDB can trigger AWS Lambda whenever there is data added, modified, and deleted in the table.
- Helps you to schedule the event to carry out the task at regular time pattern.
- Modifications to objects in S3 buckets
- Notifications sent from Amazon SNS.
- AWS Lambda can be used to process the CloudTrail logs
- API Gateway allows you to trigger AWS Lambda on GET/POST methods.
AWS Lambda Concepts
Function:
A function is a program or a script which runs in AWS Lambda. Lambda passes invocation events into your function, which processes an event and returns its response.
Runtimes:
Runtime allows functions in various languages which runs on the same base execution environment. This helps you to configure your function in runtime. It also matches your selected programming language.
Event source:
An event source is an AWS service, such as Amazon SNS, or a custom service. This triggers function helps you to executes its logic.
Lambda Layers:
Lambda layers are an important distribution mechanism for libraries, custom runtimes, and other important function dependencies. This AWS component also helps you to manage your development function code separately from the unchanging code and resources that it uses.
Log streams:
Log stream allows you to annotate your function code with custom logging statements which helps you to analyse the execution flow and performance of your AWS Lambda functions.