Resource Monitoring using AWS CloudWatch, SNS topics, EC2

Lets keep an eye on our AWS resources in the cloud and automate actions based off our CloudWatch alarms.

Reginald Bratton
8 min readNov 4, 2023

[Hello World]

Reginald Bratton INC has created a portfolio of global clients. We’ve built relationships and it has been essential to our growth. We’ve had several business referrals in the last few months. That would bring us back to the City of Charlotte. The City of Charlotte has reached out to us….

reliability is one of the well-architected pillars of AWS
power outages=No bueno
Discovery questions are important…find the root cause
We have our work cut out for us
Lets get this party started with a solution…CloudWatch
Auto alarms will be sent out. No manual actions needed
Alarm invoke=sends out SNS messages
Automation is the way of the future!
Easy Peesie :)

Quick example of how this will look behind the scenes:

Using CloudWatch we will set up the Alarm for CPU utilization…If the CPU used is more than (>) 80 there will be a (alarm) email (Amazon SNS) sent to the users that your topic of CPU usage (>) 80 has been invoked. You can view the Topic as your bookmark or threshold for your AWS resources. Remember we do have Amazon SNS and Amazon SES is a cloud-based email service provider that can integrate into any application for high volume email automation. Whether you use an email software to send transactional emails, marketing emails, or newsletter emails. For this lesson we are using Amazon SNS (simple notification service) if you need a refresher on SNS I have you covered! click here

Another brief example of our behind the scenes action:

Under CloudWatch if you set up a topic (Alarm for memory utilization) of if your memory used exceeds or (>) than 500M that your Amazon EC2 instance/server will automatically restart. Again there will be Amazon SNS message sent that your topic/alarm has been exceeded. The beauty of CloudWatch!

Ok so lets get started! The City of Charlotte is trying to prevent power outages around the city. They want to be notifed when a resource in the cloud is close to capacity and they want create an automated response before the resource is overloaded to prevent an power outage.

To get started we need to first:

1. Investigate default monitoring of EC2 instances

Lets start with Server_1…can repeat for Server_2 and Server_3
CPU is highlighted with you can see other resources are present
As mentioned before you can repeat for the other Servers

2. Create Amazon CloudWatch dashboard with widget….

CloudWatch Activated
PowerPlantMetrics

Remember our goal to help the City of Charlotte they are trying to prevent power outages for their customers around the city and surrounding areas

Widget set up…

with widgets you can create a Bar graph, pie chart etc this will help you visually see your alarms impact

3. Create CloudWatch alarm for CPU utilization

To set up the CPU alarm lets get started!

Metrics include: CPU usage or memory etc
We will set up a alarm for memory usage as well

4. Create CloudWatch action to send an email notification by using Amazon SNS

Select the server that you want the alert to be based from

Now you need to build the conditions of the alert

More configuration along with your email to get the SNS message from your topic that you have made

Now remember we will use the EC2 action in our DIY. This is when your action has a reaction meaning if you set up a alarm for memory utilization and that threshold is met you can configure your EC2 to reboot in our case or another action

But we are doing high CPU usage not memory just yet

Before you press enter review your metrics and name

BOOM…CPU usage alarm is set now you will get an email with the Amazon SNS.

Completed our 4 steps for the City of Charlotte. Now whenever there is a lot of network traffic you will get SNS messages about the usage of resources. The usage of the resources will let their city manager know that I need to right-size my instance (EC2) or add more resources (scale up) and also you will know exactly where traffic that is coming from. Also we set up the auto response if memory exceeds 500M that our server will start back over at 0 and can be filled back up to capacity to 500M

DIY…use what we have learned in previous steps

1.Add a CloudWatch dashboard for memory utilization (mem_used).

Select all servers then type in mem_used then press actions and add to dashboard

Name your dashboard…make sure the spelling is ACCURATE

SAVE

2. Create CloudWatch alarm for memory utilization (mem_used) over 500M( 500,000,000)

Head back to CloudWatch then Alarms. Type in mem-used

Select server 1 and select metric

scroll down

Our mission goals are memory used over 500M. You will need greater than not equal and static because we have a number in place. Enter in 500M

Press Next then you can set up your EC2 action to the alarm you have placed

scroll down

This is where you complete step 3…configure EC2 Action to reboot instance if memory exceeds 500M

Reboot the instance (EC2) is what we need.

Now you have to name and describe the alarm. This is to reboot our server once memory exceeds 500M to prevent an overload that turns into a blackout. The reboot starts the memory caching over at 0 back up to 500M.

Select Next then:

Now you need to preview your alarms before you set them:

scroll down

Greater than 500M and actions include reboot instance and SNS message to my email

step 2–3
step 3–3 now create alarm!
quick edit from out to *our. The beauty of editing before launching

Now I have two alarms set!

Be advised you will receive emails to the email you have provided for Amazon SNS to send if you alarm has passed a threshold you have placed.

I AM ONLY SHARING BECAUSE THIS IS A LAB….NEVER SHARE YOUR RESOURCES!

Head back over to your EC2 because you need the instance ID

edit time

I need to visit CloudWatch alerts…make sure you check your spelling of your resources…I misspelled mem_used…picture below

Success but there is a lesson within a lesson here!

When you are creating resources you have to make sure your spelling is 100% accurate!

For my metric name I had added some unfamiliar characters to it and the verification process blocked me! It has to say mem_used…..nothing else nothing more

Reginald Bratton INC is building this city!

If you need my services click here

For our mission today we accomplished…

Now give yourself a hand!

Cheers Mate!

Thanks for following along with me!

--

--