AWS Lambda can be used for endless application scenarios:
- Web applications: Instead of a maintaining a dedicated instance with a web server to host your static website, you can combine S3 and Lambda to benefit from scalability at a cheaper cost. An example of a serverless website is described in the following diagram:
An alias record in Route 53 points to a CloudFront distribution. The CloudFront distribution is built on top of an S3 Bucket where a static website is hosted. CloudFront reduces the response time to static assets (JavaScripts, CSS, fonts, and images), improves webpage load times, and mitigates distributed denial of service (DDoS) attacks. HTTP requests coming from the website then go through API Gateway HTTP endpoints that trigger the right Lambda Function to handle the application logic and persist data to a fully managed database service, such as DynamoDB.
- Mobile and IoT: A schematic for building a sensor application, which measures the temperature from a realtime sensor-connected device and sends an SMS alert if the temperature is out of range, can be given as follows:
The Connected Device will ingest data to AWS IoT. AWS IoT rules will invoke a Lambda Function in order to analyze the data and publish a message to an SNS Topic in case of emergency. Once the message is published, Amazon SNS will attempt to deliver that message to every endpoint that is subscribed to the topic. In this case it will be an SMS.
- Data ingestion: Monitoring your logs and keeping an audit trail is mandatory, and you should be aware of any security breaches in your cloud infrastructure. The following diagram illustrates a realtime log-processing pipeline with Lambda:
The VPC Flow Logs feature captures information about the IP traffic going to and from network interfaces in your VPC and ships the logs to Amazon CloudWatch Logs. AWS CloudTrail maintains records of all AWS API calls on your account. All logs are aggregated and streamed to AWS Kinesis Data Streams.
Kinesis triggers Lambda Functions, which analyze logs for events or patterns and send a notification to Slack or PagerDuty in the event of abnormal activity. Finally, Lambda posts the dataset to Amazon Elasticsearch with a pre-installed Kibana to visualize and analyze network traffic and logs with dynamic and interactive dashboards. This is done for long-term retention and to archive the logs, especially for organizations with compliance programs. Kinesis will store logs in S3 bucket for backup. The bucket can be configured with a life cycle policy to archive unused logs to Glacier.
- Scheduling tasks: Scheduled tasks and events are a perfect fit for Lambda. Instead of keeping an instance up and running 24/7, you can use Lambda to create backups, generate reports, and execute cron-jobs. The following schematic diagram describes how to use AWS Lambda to perform a post-processing job:
When a video arrives at an S3 bucket, an event will trigger a Lambda Function, which will pass the video filename and path to an Elastic Transcoder pipeline to perform video transcoding, generate multiple video formats (.avi, .h264, .webm, .mp3, and so on), and store the results in an S3 bucket.
- Chatbots and voice assistants: You can use a Natural Language Understanding (NLU) or Automatic Speech Recognition (ASR) service, such as Amazon Lex, to build application bots that can trigger Lambda Functions for intent fulfillment in response to voice commands or text. The following diagram describes a use case for building a personal assistant with Lambda:
A user can ask Amazon Echo about its to-do list. Echo will intercept the user's voice command and pass it to a custom Alexa Skill, which will carry out speech recognition and transform the user's voice commands into intents, which will trigger a Lambda Function that in turn will query Trello API to fetch a list of tasks for today.
Due to Lambda's limitation in terms of memory, CPU, and timeout execution, it's not suited for long-running workflows and other massive workloads.