Sunday, April 19, 2015

AWS Lamdba - Basics

What is Lambda: 

AWS lambda is a service that runs your code which respond to events without you managing the infrastructure (You don’t have to worry about the server at all). It responds to events such as image upload, web site click, 

What is Lamda function: 

The code (i.e., function) you run on AWS lamda is called a lama function. They are stateless. You can write your code on top of services such as S3, dynamoDB table, kinesis or SNS notification. 

What language should I learn: 

  • Javascript. 

How is lambda function called:

Lambda function is called using 2 approaches: 
  • Push: 
External system asynchronously triggers lambda to do something. 

  • Pull: 
Lamda looks for data stream changes and triggers it. Example could be it could see a change in the data in dynamodb and kinesis. 

You can also invoke lambda functions using AWS API or using the command line. 


Features: 

  • Run your code without managing infrastructure. 
  • Respond to events quickly, within milliseconds of an event. 
  • thousands of functions can run in parallel. 
  • Runs your code only when needed. 
  • Cost effective and efficient - charges a low fee per request
  • Automatic scaling: (no limit on the no. of request your code can handle).
  • Runs within milliseconds of an event. 
  • You can also choose the amount of memory your lambda function can handle. 

Where is lamda normally used: 

  • you can watch for a pattern change and trigger an alert. (i.e., from data stream updates from Kindesis or DynamoDB). 
  • perform nightly archive cleanups. 
  • can be triggered from events from connected devices, you can create an SNS notification when a smart thermosta 

OK, where do I write code: 

You can write the function code directly in the AWS lambda console or you can upload the code. Uploading will be required mainly if you your code depends on some libraries and you want to upload the code with the library. 

How do I write my code in local and upload.

  • Install required libraries by using npm install commands. 
  • Create Javascript code. 
  • Zip the entire folder which includes the code and the libraries. 
  • Attach a role to the function (can do this in the console. This is required since you might need permission to use AWS services (such as read/write to an image from S3). 

Ok, How do I test my event: 

Lamda console provides option to write test event code and test the function. 

Hmmm, how do I know how many requests has been made. 
Lambda provides a console where you can see the request count, request duration and execution error count. 

Limitations: 

  • Only available runtime is NodeJS
  • Need to be a javascript programmer. 
  • Only standard AWS events are there - S3, Kinesis, DynamoDB. 
  • Debugging can be tricky. 


Costing: 

  • You are charged based on the no. of requests and the time taken by the code to execute. 
  • Free tier includes 1M free requests per month. 
  • $0.2 per 1 million requests thereafter. 
  • The price also depends upon the time taken to execute and how much memory it uses. 
  • You are charged $0.00001667 for every GB second. 

Some interesting links: 

Home page: https://console.aws.amazon.com/lambda/home?region=us-east-1#/

1 comment:

  1. Nice post,and good information Thanks for sharing
    further check it once at AWS Online Training

    ReplyDelete