Many use cases of Modern infrastructure and application scenarios are inherently event-driven or can be represented with an event-driven model. For example, we want to send welcome emails for new user creation, scale our systems up or down whenever certain monitoring metrics are hit, or send out notifications to the project team when new accounts are created for our system. All these tasks come with operational overhead and complexity to deal with
Managing these events would require a complex infrastructure, so often we simply put them together in one controller action or use observers that run in the same processes as our applications. This makes the code base more complex as many small parts start getting interwoven and leads to a tightly linked code pattern. Apart from that, Infrastructure needed to manage these tasks invites lots of overheads
AWS as Largest Cloud Provider can help you overcome this overhead with what are called AWS LAMBDA Functions
AWS Lambda is an event-driven serverless compute service. The code that you run on AWS Lambda can execute without the need for users to manually provision or manage servers.
How does AWS Lambda work in practice?
1. First, users upload their program code to the AWS Lambda platform, or write code in Lambda’s dedicated editor (IDE). This code is known as a “Lambda function.”
2.Next, users set the Lambda function to execute in response to a given event, request, or trigger (i.e. “event source”).
3.The Lambda function will execute inside a container only when the given event or trigger occurs. AWS Lambda is responsible for provisioning the server and shutting it down upon the Lambda function’s termination.
For example, you could set a trigger every time someone uploads an image to a particular Amazon S3 storage bucket. When a new image arrives, your Lambda function can resize it and convert it into a thumbnail image.
Serverless computing solutions like AWS Lambda are also useful for time- and resource-intensive processes. Rather than running at scheduled intervals, you can set your processes to run only when new data arrives, so that you are not wasting compute resources on the same set of data.
By default, AWS Lambda includes the following runtime environments: Node.js, Python, Ruby, Java, Go, and .NET. You can also use other programming languages with a custom runtime interface.
AWS Lambda Mode of Operation
Asynchronous/Event-driven:
Lambda functions can be run in response to an event in asynchronous mode. Any source of events, such as S3, SNS, etc. will not block and Lambda functions can take advantage of this in many ways, such as establishing a processing pipeline for some chain of events. Depending on the source, events will be pushed to a Lambda function from the event source, or polled for events by AWS Lambda.
Synchronous/Request->Response:
For applications that require a response to be returned synchronously, Lambda can be run in synchronous mode. Typically this is used in conjunction with a service called API Gateway to return HTTP responses from AWS Lambda to an end-user, however Lambda functions can also be called synchronously via a direct call to AWS Lambda.
AWS Lambda functions are uploaded as a zip file containing handler code in addition to any dependencies required for the operation of the handler. Once uploaded, AWS Lambda will execute this code when needed and scale the number of servers from zero to thousands when required, without any extra intervention required by the consumer.
AWS Lambda Use Cases
You can use AWS Lambda in a variety of situations, including but not limited to:
· Log transfers where a lambda function is invoked every time there is a new log event in CloudWatch to transfer the logs into tools like Elasticsearch like Kibana
· A website where you can invoke your Lambda function over HTTP using Amazon API Gateway as the HTTP endpoint.
· Mobile applications where you can create a Lambda function to process events published by your custom application.
AWS Lambda — Key Capabilities
Some of the most common use cases are given below which align with Lambda Function capabilities.
Data processing. Lambda functions are optimized for event-based data processing. It is easy to integrate AWS Lambda with datasources like Amazon DynamoDB and trigger a Lambda function for specific kinds of data events. For example, you could employ Lambda to do some work every time an item in DynamoDB is created or updated, thus making it a good fit for things like notifications, counters and analytics.
Task automation. With its event-driven model and flexibility, AWS Lambda is a great fit for automating various business tasks that don’t require an entire server at all times. This might include running scheduled jobs that perform cleanup in your infrastructure, processing data from forms submitted on your website, or moving data around between different datastores on demand.
Scalable APIs. When building APIs using AWS Lambda, one execution of a Lambda function can serve a single HTTP request. Different parts of the API can be routed to different Lambda functions via Amazon API Gateway. AWS Lambda automatically scales individual functions according to the demand for them, so different parts of your API can scale differently according to current usage levels. This allows for cost-effective and flexible API setups.