Introduction to AWS Lambda

AWS Lambda: Run code without thinking about servers

3 min read ⋅ 163 views

AWS Lambda is a  compute serverless service that will run your code, respond to different events and also manages all of the needed resources automatically. The name "serverless computing" is used because the server management and capacity planning decisions are completely hidden from the developer or operator. Serverless contrasts with traditional cloud computing where the administrators are responsible for directly managing and maintaining virtual servers. This means that your application still runs on servers, but all the server management is done by AWS. 

AWS Lambda Features

AWS Lambda offers a free maintenance and highly-available computing environment. Developers and dev-ops no longer need to manage remote access(SSH), to fix and update security patches or work on failed virtual machines. AWS Lambda automatically scales your application by running code in response to each trigger. AWS Lambda code runs in parallel and also individually processes each trigger that allows scaling with the size of the workload. The code you run on AWS Lambda is called a “Lambda function.” When you create your Lambda function it is always ready to run as soon as it is triggered. Every AWS Lambda function contains specific configuration and information, code and also name of the function, description, requirements and it's entry point. In the beginning, AWS Lambda supported only NodeJS but right now it supports Python, Java (Java 8 compatible), C# (.NET Core) and Go, with support for other languages coming in the future. Amazon Lambda offers sample code for extract, transform, load data, real-time file processing, real-time stream processing. You can build serverless backends using AWS Lambdas (IoT Sensors), mobile Backends (Media APPs or web-Apps), you can use Lambda to thumbnail images, transcode videos, index files, process logs, validate content, and aggregate and filter data in real-time. Also, Lambda can be directly triggered by AWS services such as S3, DynamoDB, Kinesis, SNS, and CloudWatch.

Chief product strategist at Amazon Web Services Matt Wood said that:

“There’s a particular category of usage, where the developer wants to focus primarily on adding functionality to their application, they don’t want to worry about scaling up and down (infrastructure), and they want costs that run in line with usage of their application, not the utilization of their infrastructure so Lambda provides a really good answer for developers looking for that sort of focus.”

AWS Lambda example

This example is NodeJS Lamda and has one function called myExample. The console.log() statements log some of the incoming event data to CloudWatch Logs. When the callback parameter is called, the Lambda function exists only after the event loop passed is empty.

exports.myExample = async function(event, context) {
console.log("x = " + event.key1);
console.log("y = " + event.key2);
return "Success message”;
// or
// throw new Error(“Error message”);
}

To test this Lambda example:

  1. In the console, create a Lambda function using the following information:
  2. Use the hello-world blueprint.
  3. This example uses NodeJS version 6.10 as the runtime but you can also select a higher version of NodeJS. The code samples provided will work for any version.
  4. Copy this code and create the function.
  5. Test the Lambda function using the Sample event template called Hello World provided in the Lambda console.

AWS Lambda pricing

With AWS Lambda you pay per use, so that means you will pay for the requests served and the compute time required to run your code. Billing is metered in increments of 100 milliseconds, making it cost-effective and easy to scale automatically. Cost of Lambda function is determined by the number of executions ($0.20 per million), duration of execution, data transfer, allocated memory for the function( range between 128 MB and 1,536 MB). The Lambda free tier includes 1 M free requests per month and 400,000 GB-seconds of compute time per month. For more information check AWS Lambda pricing.

AWS Lambda alternatives:

  • Azure Functions was launched by Microsoft in 2016 to compete with AWS Lambda.
  • Google Cloud Functions was launched in the 2016 but it is still in the Beta phase.
  • IBM OpenWhisk is an open-source FaaS solution also released at the beginning of 2016.
  • Auth0 Webtask is a lightweight, very simple and very secure way of running isolated backend code that easily reduces the need for a backend.

Want to Learn more?

The best way to get started with AWS Lambda is to work through the Developer Guide.



JavaScript AWS



MORE ARTICLES

Comparison of Continuous Integration Tools

A review of the features offered by Travis CI and Circle CI

Primitive Data Types in Python 3

Introduction to Python 3 primitive data types

Continuous Integration: code quality and code review tools

Continuous integration best practices tools