Lambda
AWS Lambda is a compute service that lets you run code without provisioning or managing servers.
Lambda executes your code only when needed and scales automatically to a few to a 1000 lambda functions concurrently is seconds. You pay only for the compute time you consume there is no charge when your code is not running.
Lambda is Cheap Lambda is Serverless Lambda Scales Automatically
Natively supports 7 runtime language:
- Ruby
- Python
- Java
- Go
- Powershell
- Node.js
- C#
Use Cases
Lambda is commonly used to glue different services together so the use cases are endless.
Processing Thumbnails A web-service allows users to upload their profile photo. They are stored in an $3 bucket. We can setup an Event Trigger which will invoke a Lambda which will process the Profile Photo into a Thumbnail and the store it back in the bucket.
Contact Email Form A company has a contact email form which submits form data via API Gateway Endpoint. That endpoint triggers a lambda which validates the form data and if valid will save the submission in DynamoDB and send and email notification via SNS to the company
Triggers
Lambdas can be invoked via the AWS SDK or trigger from other AWS Services
Lambda Pricing
First million requests per month are free. $0.20 per additional 1 millions requests
400,000 GB seconds free per month $0.0000016667 for every GB second **This price will vary on the amount of memory you allocate
Defaults & Limits
By Default you can have 1000 Lambdas running concurrently (You can request more)
/tmp directory can contain up to 500MB
By default, Lambda run in No VPC. You can set them to run in your own VPC but your lambda will lose internet access
You can set timeout to be a maximum of 15 minutes
Memory can be set between 128MB to a max of 3008MB at an increment of 64MB
Cold Starts
Are less than ideal
Function Versions
You can use versions to manage the deployment of your AWS Lambda functions.
eg. publish a new version of a lambda for beta testing without affecting the production version
Each version will have its own unique ARN
When you reference a Lambda use its ARN A Lambda has โ๐พ two initial versions
Qualified ARN, with the version suffix Unqualified ARN, without the version suffix
With unqualified you cannot create Aliases with Unqualified ARN Unqualified ARNS points to the Latest
Alias
Allow for friendlier name when you are accessing the lambda programmatically
Layers
Pull in additional code and content in the form of layers. A layer is a ZIP archive that contains libraries, a custom runtime, or other dependencies. You can use libraries in your function without needing to include them in your deployment package
You can have up to ๐๐พ 5 layers attached to a function all layers canโt exceed the unzipped deployment package size limit of 250 MB.