07. Lab - Cloud Watch
# Cloud Watch
In this hands-on exercise, you will create a Cloud Watch event to notify via an SNS topic when an EC2 instance is created.
Prerequisites:
- AWS account
- SNS Topic created in previous lab
Topics Covered:
By the end of this lab, you will be able to:
- Create Cloud Watch event to react to the creation of an Amazon EC2 instance
- Send SNS notification via Cloud Watch when an event occurs
Steps:
- Create CloudWatch Rule
- On the AWS Management Console page, type
cloud watchin theFind Servicesbox and then selectCloudWatch. The CloudWatch Dashboard appears. - On the left-hand menu, under
Events, selectRules. - Click
Create rule. - For
Service Name, selectEC2. - For the
Event Type, selectEC2 Instance State-change Notification. - Select the
Specific state(s)radio button. Selectrunningfrom the drop-down box.
Note: This configures the rule to trigger whenever an Amazon EC2 instance changes to the running state, which happens when an instance is launched or started. - On the right-hand side of the screen, in the
Targetsection, add a target by clicking onAdd target. - In the drop-down, change
Lambda functiontoSNS topic. - For the
Topic, select the topic you created in the SNS hands-on exercise.
Important: If the Topic doesn’t appear, theAccess policy – optionalsection doesn’t have the correct permissions to allow other services to access the Topic. - Scroll down and click the
Configure details. - Enter a name in the
Namefield. Ensure the state isEnabled. ClickCreate rule.
- On the AWS Management Console page, type
- Test CloudWatch Rule
- Navigate to the EC2 console page, by clicking on
Servicesin the upper left-hand menu. TypeEC2in the text box and click onEC2found in the search results. - On the EC2 Dashboard page, click on
Instancesin the left-hand navigation. - Click
Launch Instance. - Select the
Amazon Linux 2 AMI (HVM), SSD Volume TypeAmazon Machine Image (AMI).
Important: You are free to choose a different AMI, but to avoid excessive charges, pick one that says,Free Tier Eligible. - For the
Instance Type, select the free-tier instance type oft2.micro. - Click
Review and Launch. - Click
Launch. - Generate and download a new key pair and then launch the instance.
- Click
Launch Instances. - Click on
View Instances. - Once the Instance state changes to
Running, check your email client for an email alert from the SNS Topic.
- Navigate to the EC2 console page, by clicking on
- Cleanup & Disable EC2 Instance and Cloud Watch Rule
- To avoid recurring charges for leaving an instance running, let’s disable the EC2 instance.
- From the EC2 Dashboard, select the instance just created, click
Actions, thenInstance State, and then selectTerminate. - To avoid recurring charges for leaving the Cloud Watch rule running, let’s disable it.
- From the SNS Dashboard, select
Rulesfrom under theEventssection. - Select the Rule you just created, by clicking the radio button next to the Rule.
- Click on the
Actionsbutton, and selectDelete.
Create a Cloud Watch event to notify via an SNS topic
Task Feedback:
Excellent Job!