AWS Lambda Use Cases

Manjula Liyanage
6 min readDec 11, 2022

--

An image with AWS Lambda sign and title of the post, AWS Lambda use case

What is AWS Lambda and Why?

AWS Lambda is a service provided by Amazon Web Services (AWS) that allows developers to run their code without worrying about the underlying infrastructure. Therefore, developers can focus on writing and deploying their code rather than managing and scaling servers.

AWS Lambda functions are executed in response to specific events or triggers, such as user requests or data changes in a database. These functions are independent and can be written in various languages, including JavaScript, Python, and Java.

One advantage of using AWS Lambda is its great flexibility and scalability. Since each function is independent, it can be scaled up or down separately from the rest of the application. Additionally, cloud-native services allow easy integration with other cloud-based services, such as databases and message queues. This can make it easier to build complex, scalable applications.

So, below are some highlights:

  • Removes the need for traditional computing services
  • Reduce operational cost and easier operational management
  • Faster development
  • Auto-scaling — Lambda can scale from a single request to hundreds of thousands per second. Read this to learn more about how Lambda handles Scaling.
  • Pay as you go
  • Lambda is natively microservice; therefore, it gives an easy microservice implementation model.

Given these benefits, you should still know the limitation of Lambda. In addition, take note of known Lambda pitfalls and cost optimization tips.

Here are some Lambda use-cases

Building Serverless web apps

An architecture of a Serverless web app

Lambda functions can be used to build serverless web applications, where the application logic is split into individual tasks executed in response to specific events. This can make it easier to build scalable, flexible applications.

You can create a web API with an HTTP endpoint for your Lambda function by using Amazon API Gateway. API Gateway provides tools for creating and documenting web APIs that route HTTP requests to Lambda functions.

Other Serverless services used in this architecture:

Cognito User Pools provides features to control user sign-up, sign-in, email or SMS verification and user management with more advanced features. Users can also sign in through social identity providers like Google, Facebook, and SAML identity providers.

Cognito Identity Pool will provide temporary credentials to AWS resources like S3 using the token received on successful login.

Cognito will authorize the user with the necessary permissions for the IAM role. Learn more about user authentication and authorization with AWS Cognito.

Route 53 for managing DNS (custom domain names)

Use CloudFront distribution with S3 to serve the web app. The website must be a client-side web app such as React, Angular, or JavaScript.

Certificate manager to provision an SSL certificate and associate with CloudFront

Associate the custom domain and the SSL with the API gateway

Amazon DynamoDB is a fully-managed, high-performance, NoSQL database service that is easy to set up, operate, and scale. It is used to persist session data, such as the shopping cart and the product database. The same architecture can be extended to develop complex applications like serverless e-commerce systems.

An architecture of an e-commerce app

I’m using the Microsoft cloud-native microservice reference application with AWS services.

The application also uses a related pattern called Backends-for-Frontends (BFF), which recommends creating separate API gateways for each front-end client. The reference architecture demonstrates breaking up the API gateways based on whether the request comes from a web or mobile client.

Other Serverless services used in this architecture:

Amazon Personalize: Amazon Personalize provides similar item recommendations, search re-ranking based on user preferences, and product recommendations based on user-item interactions.

Amazon Pinpoint: Amazon Pinpoint adds the ability to dynamically send welcome messages, abandoned cart messages, and messages with personalized product recommendations to the customers.

Amazon ElastiCache: This is a session store for volatile data and a caching layer for the product catalogue to reduce I/O (and cost) on DynamoDB.

Amazon Simple Notification Service (Amazon SNS) is a managed service that delivers messages from publishers to subscribers (also known as producers and consumers).

Amazon Simple Queue Service (SQS) lets you send, store, and receive messages between services at any volume without losing messages or requiring other services to be available.

EventBridge enables you to decouple your architectures to make it faster to build and innovate, using routing rules to deliver events to selected targets.

How to achieve high availability

Document conversion

Suppose your application provides documents (invoices, purchase orders, receipts, prescriptions). In that case, your application should be capable of serving those documents in different formats, such as PDF, HTML, and CSV, depending on the requirement and the device. Instead of storing documents in all forms, you can use AWS Lambda to create the desired format of the document and serve it to the customer for a download or a display on a page.

Data processing

Lambda functions can process large amounts of data, such as logs or events. This can be useful for data transformation, aggregation, or analysis tasks.

An excellent example of this use case is a Centralized logging system where Lambda is used for logging transformation.

You can attach a Lambda function to Kinesis to transform data before sending it to the destination. You can use Lambda for Structuring data as per destination accepted format, such as adding metadata and combining data from another source. Lambda can add metadata such as SourceName, SourceType, AWS Account Number and name etc. Also, Lambda can transform the raw logs to JSON format if required. Also, it can read from an S3 bucket to get the logs in the example of Load Balancer logs. Many other sources can be integrated with Kinesis via EventBridge.

AWS Log transformation and ingestion

File processing

Lambda functions can be used to process files as they are uploaded to the cloud. For example, a Lambda function could be used to resize images, extract text from documents, or transcribe audio files.

Objects are uploaded into Amazon S3. Then the S3 bucket publishes an event notification to an Amazon SNS topic.

Amazon SNS can fan-out messages to multiple subscribers.

N number of Lambda functions can be created to process data, all without the need to provision or manage servers.

After processing, data can be sent to different AWS services for storage, further processing or analytics.

A famous example of this is how Netflix do their video encoding at scale using Lambda.

With Lambda, Netflix can use rules triggered by the movement of video assets to launch and configure the necessary processing to encode 60 different parallel streams and can use the rules and events to aggregate and deploy after all the parts are processed.

Automation

Lambda functions can be used to automate a wide range of tasks, such as backups, data migration, or data synchronization. These functions can be triggered by a schedule or in response to specific events, making it easy to automate complex processes.

Sending security alerts and email automation are two common examples.

Sending security alerts

Automation of security alerts and raising incidents

You can write a Lambda function to send an alert on a specific event from Cloudwatch/CloudTrail AWS activity logs. It will notify your designated on-call staff via email, or you could even write a code that will trigger the AWS Lambda to call you on your phone.

Email automation

Email automation

You can automate newsletters, email campaigns and transactional emails using Lambda functions and Simple Email Service SES.

--

--

No responses yet