The concept of event-driven programming is not new. But AWS Lambda takes it to the next level allowing developers to focus on the coding without having to worry about the mundane tasks of provisioning, scaling and administering the underlying infrastructure which, in AWS parlance, is the "undifferentiated heavy lifting".
AWS launched Lambda in keeping with the tradition of listening to customers. The service is designed to make it easy for developers to run code in the cloud and to connect services easily in the AWS cloud. Essentially a compute service, Lambda allows developers to build applications that will respond to events and customer requests. Thus, it seeks to simplify a coder's job in two ways: build applications that will provision and scale automatically, and build new back-end services in response to events in other AWS services or events generated by user applications.
How Lambda works
The code you run on AWS Lambda is uploaded as a "Lambda function". Building a Lambda function is as easy as three clicks: you simply run the code in Node.js, give it permission to access specific AWS resources, and then connect the function to your AWS resources. Lambda will automatically run the code in response to modifications to objects uploaded to Amazon Simple Storage Service (S3) buckets, messages arriving in Amazon Kinesis streams, or table updates in Amazon DynamoDB. Currently, Lambda enables connections to only three AWS services.
For example, at Bluepi we recently used Lambda for one of our customers who required video output in a variety of formats. So we designed a Lambda function wherein we created an S3 bucket and described the event as any new video uploads to S3 will trigger an action into Elastic transcoder that will eventually output the video into different formats.
Lambda can be accessed programmatically via the AWS console, the AWS SDKs, and from the Command Line Interface. One can write the code using the in line editor of the console or package the code as a ZIP and upload it via the CLI. Each function has associated configuration information, such as its name, description, entry point, and resource requirements. Once a Lambda function is created, it can be tested by creating a simulation of event notification from any of the data sources it connects.
Running the Lambda code to trigger a reaction to events in the AWS cloud calls for a disciplined approach. It is important to write the code as a stateless entity and ensure not to extend access to the local file system, child processes and similar artifacts beyond the lifetime of the request. This will allow Lambda to rapidly launch as many copies of the function to keep pace with incoming requests and scale. However, Lambda itself may choose to retain an instance of the function and reuse it for a subsequent function to improve performance.
It is possible to get a detailed view of the Lambda functioning via the performance metrics in Cloud Watch. What would have been really nice is a feature that will allow Lambda to trigger an action based on an SNS alarm from Cloud Watch.
Parting shot
The automated deploying and scaling in Lambda will reduce development time and infrastructure costs as only an event will trigger a function, as opposed to having a complete stack running for something that will run infrequently. At the same time, there is a trade-off between the flexibility in EC2 and the automation in Lambda. While EC2 offers myriad options in instance size and operating system and allows fine-grained control over compute resources, Lambda will automatically provision capacity and operating system according to the memory allocated to the function.
The most far reaching impact of Lambda is that the event-driven nature of the service will force developers to think differently in terms of decomposing a business problem into building micro services. At the same time, the billing parameter which takes into account the time required to complete a function and the memory allocated to achieve it will unfold a whole new way of thinking.
Gaurav is having an experience of 4+ years in writing field and wrote this article on behalf of BluePi, an Amazon consulting partner. BluePi is a leading AWS Cloud Solutions provider company in India.
Orignal From: AWS Lambda, The Event Driven Service From Amazon
No comments:
Post a Comment