Exploring AWS !!
Day 45:
AWS Lambda
AWS lambda is a serverless compute service where code is triggered in response to event occurrence and also manages underlying compute resources for us.
Features:
You don’t require servers, you just need to do is write the code and upload it to lambda.
Automatic scaling based on size of workload.
Pay what you use — amount of time the code of compute.
Concurrency — Reserved and Provisioned
Reserved concurrency guarantees the maximum number of concurrent instances for the functions.
Provisioned lets you request a certain number of execution which get initialized and prepared to respond immediately to the invocation of function.
What is AWS lambda?
comes under compute domain, allows you to execute code for any type of application, can be used to run code in response to certain events from other services, supports Java, Python, C#, Node.JS, etc.
Where its used?
In automation, like lets say used for processing the image into thumbnails when uploaded.
How does it work?
Requests sent are given to container which contains the code the user has provided to satisfy query. If multiple requests are sent then multiple containers are created.
Upload code to one or more lambda function
Lambda executes this code
After code is invoked Lambda takes care of provisioning and managing required servers.
To manually backup the data we can use lambda.
Create 2 S3 buckets → Create IAM role → Create lambda function to copy files between buckets → Testing it out.
Benefits and Limitation:
Benefits:
Serverless architecture
Code Freely
No VM needs to be created
Pay-as-you-go
Monitor performance
Limitation:
Max disk space 512 MB for runtime environment.
Memory volume varies between 128 MB and 3008 MB to function while execution.
Function timeout can be only 900 seconds (15 mins) default in 3 seconds.
Only languages available in lambda editor can be used.
Use Case:
Serverless websites, automates backups, filer and transform data
Building serverless allows to focus on code, no need to manage infrastructure
Schedule lambda events and create backups
Filter and transfer — transferring data between lambda and other Amazon services like S3, Database, Kinesis, we can filter data before sending, we can easily load and transform data.
AWS lambda with S3:
User → web → S3 → Lambda → Microservices
Demo:
Create function → provide trigger as S3 and choose bucket → Upload object to bucket → This would trigger lambda function → Go to monitoring tab under lambda console and check logs stream to confirm invocation of function.
Example of using lambda: You have different file formats like pdf, img, txt and you upload them to a S3 bucket, which is integrated with Lambda which filters the format and according to the format moves it to their specific buckets, like pdf goes to the pdf docs bucket, img goes to img bucket and txt to txt bucket.
Top comments (0)