Post Syndicated from Betsy Chernoff original https://aws.amazon.com/blogs/compute/configuring-and-using-monitoring-and-notifications-in-amazon-lightsail/
This post is contributed by Mike Coleman | Developer Advocate for Lightsail | Twitter: @mikegcoleman
We recently announced the release of resource monitoring, alarms, and notifications for Amazon Lightsail. This new feature allows you to set alarm thresholds on your Lightsail instances, databases, and load balancers. When those alarm thresholds are breached, you can be notified via the Lightsail console, SMS text message, and/or email.
In this blog, I walk you through the process of setting your notification contacts, creating a new alarm, and testing out the notifications. Additionally, you can simulate a failure to see how that is represented in the metrics graph, console, and notification endpoints.
The alarm you create during this blog notifies you whenever there are two or fewer healthy instances attached to your load balancer. In a production workload, this is a fairly critical scenario. So, you can configure Lightsail to notify you as soon as it discovers the problem.
To complete this walkthrough, you need three running Lightsail instances, placed behind a Lightsail load balancer. If you need with help getting that done, check out our documentation on instances and load balancers. Don’t worry about what’s running on your instance, it’s not important for the sake of this walkthrough.
Configuring notification contacts
To get started, create notification contacts for both email and SMS. You can create one email contact per AWS Region where Lightsail operates. If you find that you need to notify multiple people via email, you can create an email distribution list with those contacts. Then, set Lightsail to send the email notification to that distribution list.
For SMS, you can only create contacts in specific Regions. For an up-to-date list of those Regions, go here:
Let’s get started creating the notification contacts. First, log into the AWS Management Console, navigate to the Lightsail home page, and follow the steps below.
- Click Account near the top right of the Lightsail home page, and click account from the dropdown menu.
- Scroll down to the Notification contacts section and click + Add email address. Ensure that the correct AWS Region is selected.
- Enter the email address where you want Lightsail to send alarm notifications in the text box.
- Click Add contact. Then, click I understand. This signifies that you understand that a verification email is sent to the email address you entered, and that notifications are not sent to that address until it’s verified.You verify your email address in the next section.
- Scroll down and click + Add SMS number, and ensure that the correct AWS Region is selected.
- Choose the country/Region for the phone number you want to use (note: this can be different than your AWS Region), and enter the mobile number you want to receive notifications at.
- Click Add contact.
Verifying the notification contact email address
Return to the Lightsail home page. There should be a banner at the top of the page notifying you that your email address must be verified.
- Access the email account that you set up in the previous section. You should find an email with the subject AWS Notification – Subscription Confirmation
- Open the email.
- In the email body near the bottom there is a link to click to verify your email address. Click the verification link. A webpage loads, which lets you know that your email address was successfully verified.
- Refresh the Lightsail home page, and the verification banner should now be gone.
Creating an alarm
Now you have your notification contacts set. It’s time to create the actual alarm. An alarm is defined by choosing a metric to monitor, and defining a threshold value and schedule for evaluation.
In our example today, we’re going to look at the healthy host count metric. As the name implies, this metric tells us how many healthy hosts are connected to our Lightsail load balancer. In this example, there are three instances attached to the load balancer, and you want to know if one of them becomes unhealthy as soon as possible. In other words, when there are two or fewer healthy instances.
Lightsail reports metrics every five minutes. So the cadence you set to be notified is the first time the metric reports back unhealthy in any five-minute window. Follow the steps below to configure the alarm.
- From the Lightsail home page click on Networking from the horizontal menu, and then click on the name of your load balancer.
- From the horizontal menu click on Metric.
- Ensure that Healthy host count is selected from the metric dropdown menu.
- Scroll down the page and click +Add alarm
- Use the dialog box and drop-down menu to set the threshold for healthy host count to Less than or equal to 2. Set the time values so that an alarm is raised if the threshold is exceeded 1 time within the last 5 minutes.
- Leave the check boxes checked for SMS and email notifications.
- The alarm is created, but Lightsail may display a message indicating that the alarm is in insufficient data state. This disappears in a few minutes.
Test to make sure that you actually receive a notification when the alarm threshold is breached.
- To test that the notifications are configured correctly, click the three dot menu for your alarm.
- From the drop down menu, choose Test alarm notification. After a minute or two, you should get both a text and an email notification.
Triggering the alarm with a simulated instance failure
So, at this point you have an alarm set, and you know that the notifications are working properly. In this final, step you simulate a failure to ensure that it’s detected correctly by Lightsail. That the alarm then sends the appropriate notifications.
To simulate a failure, you’re simply going to stop one of the instances attached to your load balancer by following the steps below.
- Return to the Lightsail home page.
- Click on the three dot menu for one of your instances and click
- Click Stop again to confirm.
- Return to the Load Balancers metrics page, and notice that after a few minutes the graph shows a drop in the healthy host count. Shortly after the graph updates the alarm should breach, and you should receive your text and email notifications.Note: Since our alarm threshold is evaluated after 5 minutes, it may take a few minutes for the alarm to trigger and notifications to be sent.
- Once you receive your text and/or email notifications, return to the Lightsail home page. Notice there is also a notification banner at the top of the page.
- Click on the three dot menu for the instance you previously stopped, and click Start.
- Return the load balancer metrics screen and wait for the graph to update and show three healthy instances. You may need to refresh your web browser.
As mentioned previously you can create alarms for a wide variety of metrics across databases, load balancers, and instances. For a complete list of metrics, check out the Lightsail documentation.
So, that’s all there is to it. If you spun up new instances for this simulation, make sure to terminate those to eliminate extra costs. If you’ve already got some critical resources running in Lightsail, now is a good time to set up some alarms and notifications. If you don’t have anything currently running in Lightsail, why not take advantage of our free 30-day offer for Lightsail instances, and build something today. Need more? Reach out to me @mikegcoleman, and check out Lightsail’s landing page for other resources and tutorials.