Thursday 10 February 2022

Introduction to AWS Lambda

 
Falls under Compute category of AWS Services (among which are EC2, EBS, Elastic Load Balancing).
 
We only need to provide the code that needs to run on hardware. Servers are automatically provided so we don't need to provision or manage them. 

AWS Lambda platform provides automatic scaling, based on the workload, in response to each trigger it receives. 

We are charged only for the time that our application is running. 1 ms granularity is used.
 
Lambda can run any type of application or backend services. It supports many programming languages like C++, C#, Java, JavaScript, Python, Go etc... 

It can run the code (functions) in response to events received from other applications or AWS services. These events are actually requests to AWS Lambda. Requests are handled by containers which run the code written in such way to serve the query. If number of requests grows, so grows the number of containers spawned and assigned to this lambda. If number of request decreases, the smaller number of containers gets used. 

Use Case Example: Processing images uploaded to S3
  • image is uploaded to S3 bucket
  • this triggers AWS Lambda 
  • lambda function processes the image and formats it into a thumbnail adjusted for the device it will be showed on (mobile, tablet, PC)

Use Case Example: Extracting trending social media hashtags

  • social media data e.g. hashtags is added to Amazon Kinesis (streaming data processing platform)
  • this triggers AWS Lambda 
  • data is stored in DBs for further processing

Use Case Example: A near real-time data backup system

  • the goal is to save a copy of a document in a temporary storage system as soon as it's uploaded to server
  • create two S3 buckets: one where data is uploaded and another one for storing its copy
  • to allow these buckets talk to each other we need to set up Identity and Access Management (IAM) roles and policies
  • the code which copies data between buckets will be in Lambda function
    • this Lambda function is triggered each time a document is uploaded to first S3 bucket

 

How it differs from EC2? 

How to decide when to use EC2 and when Lambda?


Resources:



No comments: