What Can You Do With AWS Lambda?

AWS Lambda is a popular serverless compute service. Its one of the fastest growing services in all of AWS according to Andy Jassy (CEO of Amazon). But what can you actually do with it? In this article, we’ll look at the Top 5 most popular use cases for AWS Lambda.

Visual Learner? Check out my video below on this topic.

#5 – API Hosting Via API Gateway

API Logo - LogoDix
APIs without the need for managing machines? Where do I sign!?

APIs are the bread and butter of the internet. They’re how services communicate with one another whether its through the browser or machine to machine.

Integrating an API Gateway in front of a Lambda function allows you to build rest or HTTP apis that you can access from the public internet via common XHR libraries. Prior to Lambda, application developers would often use Amazon EC2 to host the compute for their APIs and distribute traffic using AWS Load Balancers. This was not cost effective and provided additional administrative burden – after all, more components, more problems.

AWS Lambda provides the load balancer and the compute to host your compute logic. Its a neat simplification that reduces the number of moving parts you have to worry about so that you can focus more on your business.

To learn more about how to setup Lambda with API Gateway, check out the two videos below:

  1. Build a REST API With API Gateway and Lambda
  2. Build a HTTP API with API Gateway and Lambda
  3. REST vs HTTP APIs? Whats the Difference?

#4 – Serverless CRON Jobs with Cloudwatch Events

CRON jobs are a powerful tool to perform tasks on some regular cadence. Popular use cases are for nightly database maintenance, and other routine tasks.

You can integrate Lambda with Amazon Cloudwatch Events which use CRON expressions to define their cadence. You can also add a Lambda function as a trigger which you can invoke with a custom input whenever the timer fires.

Scheduling Serverless Data Streams Using Lambda, Cloudwatch Events
Serverless CRON Jobs are a cost effective way to perform recurring tasks without managing infrastructure.

Similar to the past, there’s a whole bunch of utilities for timer-based jobs in the cloud. This can range from maintenance to actual application logic (i.e. calculate dashboard totals once every hour).

Here’s my YouTube tutorial video on how to set up a Cloudwatch Event that triggers a Lambda Function on AWS.

#3 – Event Processing with SQS / SNS

SQS stands for Simple Queue Service. It is a serverless message orchestration service that lets ‘consumers’ poll from the queue to process messages.

Messages can be anything, but often contain application events that require processing. For example, in a credit card processing architecture, we may have a TransactionReceiver service that enqueues messages onto a SQS queue, so that the TransactionProcessor service can actually process it. This is a very common pattern in distributed cloud based systems.

With Lambda, you can integrate SQS as an event source. This means that anytime messages are delivered to your SQS queue, Lambda will poll the queue for the message and trigger your Lambda Function – passing in the SQS event body into your function’s arguments.

Working with AWS Lambda and SQS · LoginRadius Engineering
Lambda and SQS are one of the most popular combinations for Serverless Event Processing on AWS. Messages added to the queue immediately get automatically processed by Lambda.

From there, you can perform your business logic unique to your application. The neat thing is, Lambda does a really good job at scaling if you have requirements for very highly concurrent applications (i.e. Thousands of messages per second).

SNS or Simple Notification Service plays a similar role, except that there is no queue, and messages are delivered directly from your SNS topic to your lambda via an Invocation. SNS and Lambda integration is kind of an anti-pattern these days due to throttling concerns, so you should generally avoid it and stick to SNS for event processing.

Here’s some videos from my YouTube channel on SNS vs SQS and how to integrate these services with AWS Lambda:

  1. SNS vs SQS – Whats the Difference?
  2. How to Setup SQS + Lambda on AWS
  3. How to Setup SNS + Lambda on AWS

#2 – File Upload Processing With Amazon S3

Amazon S3 is Simple Storage Service. Its the oldest AWS service in existence and the most popular. Its role is to be a serverless object storage service for you to store files of any size. This can include website asset files, images, videos, word documents, and more.

Many applications these days allow clients to upload content to S3. As an example, you can think of an image processing application that allows a User’s images to be submitted for processing, and a report generated afterwards.

With Amazon S3, you can setup Object Triggers such that when a file is Uploaded to S3, S3 will automatically trigger your lambda function and pass in the bucket/key of the S3 object you just created.

In our previous example, this would allow us to process a user’s image on upload and generate a report that can be fed back to them upon completion. This pattern is a common one in applications that need to perform long running jobs based on a customer’s action such as generating a PDF report.

S3 also supports other object creation modification triggers such as modifications and deletions.

Here’s one of my earlier videos setting up an S3 Object Creation + Lambda Trigger.

#1 – Glue Logic For Step Function Workflows

AWS Step Functions is an orchestration service that lets you build and run complex event processing workflows. The service is predated by is predecessor – SWF or Simple Workflow Service that was the only workflow service offered by AWS for many years.

Step Functions are the new kid on the block in the workflow world and they can easily be integrated with AWS Lambda to perform ‘glue logic’ as part of a workflow lifecycle.

For example, you can create a workflow state machine for a credit card application that performs a series of steps:

  1. Validate the credit card transaction
  2. Perform the transaction by calling a third party service
  3. Store the Result

Steps one, two, and three can all be executed as part of an AWS Lambda function in order to facilitate the workflow. In this case, you would likely have 3 separate lambda functions – one for each step – and integrate them into your workflow respectively.

New – AWS Step Functions Workflow Studio – A Low-Code Visual Tool for  Building State Machines | AWS News Blog
An example of a step function workflow incorporating AWS Lambda, DynamoDB, and SNS.

This is a simple example but the possibilities are really endless here to incorporate step functions into your application. To learn more about AWS Step Functions and how they can be integrated with AWS Lambda check out the videos below:

  1. Step Function Overview
  2. Start a Step Function from Lambda

Summary

In this article, we discussed some of the most popular use cases for AWS Lambda. It really doesn’t stop here though – Lambda is such a versatile service that I would consider it base knowledge for anyone trying to learn or get a job in AWS.

As new services are released into the AWS ecosystem, Lambda will continue to play a pivotal role in simplifying your application development process, and making it easier to run your applications at scale.

If you enjoyed this article, be sure to check out some of my other articles and YouTube channel for more AWS content.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts