Serverless Architectures using Amazon CloudWatch Events and Scheduled Events with AWS Lambda
SPL-119 Version 2.2.9
This lab demonstrates how to create serverless infrastructure that can monitor your cloud infrastructure and respond to events.
In the first part of this lab, you will learn how to use an AWS Lambda function with Amazon CloudWatch Events to react to the creation of an Amazon EC2 instance.
In the second part of this lab, you will create an AWS Lambda function that can monitor a website and alert you when it is not responding correctly.
By the end of this lab, you will be able to:
- Create an AWS Lambda function
- Configure Amazon CloudWatch Events
- Configure an Amazon CloudWatch Alarm
- Configure Amazon Simple Notification Service (SNS) to send notifications
Technical knowledge prerequisites
To successfully complete this lab, you should be familiar with Amazon EC2. Node.js programming is required, although full solution code is provided.
Other AWS Services
Other AWS Services than the ones needed for this lab are disabled by IAM policy during your access time in this lab. In addition, the capabilities of the services used in this lab are limited to what’s required by the lab and in some cases are even further limited as an intentional aspect of the lab design. Expect errors when accessing other services or performing actions beyond those provided in this lab guide.
Introducing the Technologies
AWS Lambda is a compute service that provides resizable compute capacity in the cloud to make web-scale computing easier for developers. You can upload your code to AWS Lambda and the service can run the code on your behalf using AWS infrastructure. AWS Lambda supports multiple coding languages: Node.js, Java, or Python.
After you upload your code and create a Lambda function, AWS Lambda takes care of provisioning and managing the servers that you use to run the code. In this lab, you will use AWS Lambda as an event-driven compute service where AWS Lambda runs your code in response to changes to data in and SNS topic and an Amazon S3 bucket.
You can use AWS Lambda in two ways:
As an event-driven compute service where AWS Lambda runs your code in response to events, such as uploading image files as you’ll see in this lab.
As a compute service to run your code in response to HTTP requests using Amazon API Gateway or API calls.
Lambda passes on to you the financial benefits of Amazon’s scale. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. With these capabilities, you can use Lambda to easily build data processing triggers for AWS services like Amazon S3 and Amazon DynamoDB, process streaming data stored in Amazon Kinesis, or create your own back end that operates at AWS scale, performance, and security.
AWS Lambda Blueprints
Blueprints are sample configurations of event sources and Lambda functions that do minimal processing for you. Most blueprints process events from specific event sources, such as Amazon S3 or DynamoDB. For example, if you select an s3-get-object blueprint, it provides sample code that processes an object-created event published by Amazon S3 that Lambda receives as parameter.
When you create a new AWS Lambda function, you can use a blueprint that best aligns with your scenario. You can then customize the blueprint as needed. You do not have to use a blueprint (you can author a Lambda function and configure an event source separately).
CloudWatch Events delivers a near real-time stream of system events that describe changes in AWS resources. Using simple rules that you can set up in a couple of minutes, you can easily route each type of event to one or more targets, including AWS Lambda functions with less overhead and greater efficiency. You can think of CloudWatch Events as the central nervous system for your AWS environment. It is wired in to each of the supported services, and becomes aware of operational changes as they happen. Then, driven by your rules, it activates functions and sends messages to respond to the environment.
Amazon Simple Notification Service (SNS)
Amazon SNS is a notification service that provides significant advantages over the complexity of developing custom messaging solutions or the expense of licensed software for systems that need to be managed and maintained on site. It runs within Amazon’s proven network infrastructure and data centers, so topics will be available whenever applications need them. To prevent messages from being lost, all messages published to Amazon SNS are stored redundantly across multiple servers and data centers. Amazon SNS allows applications and end users on different devices to receive notifications via mobile push notifications, HTTP/HTTPS, Email/Email-JSON, SMS or Amazon SQS queues, or AWS Lambda functions.
Join Qwiklabs to read the rest of this lab...and more!
- Get temporary access to the Amazon Web Services Console.
- Over 200 labs from beginner to advanced levels.
- Bite-sized so you can learn at your own pace.