An Introduction to AWS Lambda

What is AWS Lambda?

AWS Lambda is serverless compute service offered by Amazon Web Services. It lets you run the code without provisioning the servers in advance. The code which users run on AWS Lambda are called functions. Each functions runs in a self contained environment and uses a runtime defined by the user. The concept of serverless means not needing to provision the servers while running your code. Users can upload there code and select the runtime they want to use to run the code, AWS Lambda will take care of all the other stuff. Users will pay for what they use.

Why do I need AWS Lambda?

AWS Lambda is an essential part of the serverless architecture. If you want to use serverless architectures and don't want the headache of maintaing servers, AWS Lambda empowers you to run your code without worrying about much. There are many runtimes supported by it and many more will come in future. There are some use cases for which AWS Lambda is a good option but with some use cases you might want to choose something else.

What are the use cases for AWS Lambda?

AWS Lambda works best when there are events to process. Following are some good use cases for AWS Lambda:

  • Data Processing: AWS Lambda can respond to events like change in data, change in state or something a user does. It can directly integrates with AWS Services like SNS, SQS, change streams from DynamoDB etc. All these events can be selected as a source to fire off the Lambda funtion to take some actions related to it.
  • Real Time Processing: Be it real time file processing or stream processing, AWS Lambda can not only handle the processing in these cases but can also scale as per the requirement. The S3 upload event or a data published to Kineses stream can be used as an event to process the data further.
  • Web Applications: AWS Lambda can also be triggered using the the request coming to an AWS API Gateway. This means AWS Lambda can be used to create highly scalable APIs which can scale easily with the traffic demand for the app.
  • Task Automation: Due to its event based triggers functionality, AWS Lambda are a good fit for various business task automations for which you don't need servers running all the time. An example will be, sending an onboarding email whenever a user joins your app.

What are some benefits of AWS Lambda?

We have touched on this in the above questions in this article. Let's talk about them in little bit detail:

  • Pay Per Use: You only pay what you use in AWS Lambda. At the writing of this article, AWS Lamdba is charged based on the 100ms cycle. That means you will be charged for min 100 ms and then for every next 100 ms irrespective to your actual use. We have an event coming at the end of this month hopefully AWS will come up some good announcements related to the pricing.
  • Managed Infrastructure: The AWS Lambda infrastructure is managed by AWS and users don't have to maintain anything. This means as a user, you don't have to think about maintaing the underlying servers, patching of those servers, scaling of those servers etc. This can be a huge cost and time saving for some of the users.
  • Intergation With Other AWS Services: Like I mentioned earlier, AWS Lambda can be triggered from many AWS services. It is a good thing as you can now respond to the events happening in other part of your code using those services.

What are some limitations of AWS Lambda?

There is no service which only have benefits. There are always some limitations and AWS Lambda also has some. Following are some of the limitations of AWS Lambda:

  • Cold Starts: It is the amount of latency between when the event is generated and when the function actually executes it. This happens because, a function first needs to be downloaded into one of the servers managed by AWS and a runtime is allocated to run the function. This inludes downloading of the code and other init procedures defined in the code to make sure the handler function is ready to take the event. Though it depends on many factors but increase in latency makes AWS lambda not suitable for the latency critical task and applications.
  • Execution Time: The Lmabda function will timeout after running for 15 minutes. There is no way to increase it. You can define a timeout less than 15 mins but the ot more than that. If your task requires more than 15 mins to complete, you should look for any other options.
  • Code Package Size: There is a size limit on Lambda code package. It is 50 MB (zipped, for direct upload), 250 MB (unzipped, including layers) and 3 MB for (console editor).
  • Concurrency: A single AWS account can run 1000 Lambda function concurrently. This is a default limit. You can ask AWS raise the limit, but if you hit the limit before that, your executed funtions above the limit will be throttled and forced to wait until other functions completes their job.

What is Next?

If you have now decided to give AWS Lambda a spin, here is a link from AWS to start working with AWS Lambda functions. Getting Strated with AWS Lambda. I will be posting more about the Lambda functions in this blog in near future.

I would love to hear what you think about this article and if there anything you would like me to cover in future. Drop me a line on @awsmag.