Monitoring Memory (RAM) with AWS ElasticBeanstalk EC2 Instances & Cloudwatch

If you are like me, you are wondering why in the world Amazon Web Services Cloudwatch service doesn’t allow you to monitor memory usage?  Luckily they do allow you to use custom Perl scripts to create your own custom metrics. The following instructions will show you how to setup memory monitoring on your ElasticBeanstalk EC2 instances in less than 5 minutes. This uses the scripts from here as a resource and shows you how to use them within your AWS ElasticBeanstalk Environment.


Step 1: Setup an IAM fole for your ElasticBeanstalk environments.

First, click your name in the top right of the AWS console and go to Security Credentials. On this page, click roles on the left and assign your aws-elasticbeanstalk-ec2-role CloudWatch Full Access.


Next, go into your ElasticBeanstalk environment (repeat for each environment) and assign the role you gave Cloudwatch access to above:



Step 2: Add the following to your GIT Repo

Add this in a folder named .ebextensions at the root of your repo and give it a filename of 15-memorymonitor.config.

    command: "wget"
    ignoreErrors: true
    command: "unzip"
    ignoreErrors: true
    command: "rm"
    ignoreErrors: true
    command: "mv aws-scripts-mon/ /home/ec2-user"
    ignoreErrors: true
    command: "crontab -l | { cat; echo '* * * * * /home/ec2-user/aws-scripts-mon/ --mem-util --mem-used --mem-avail'; } | crontab -"
    ignoreErrors: false


Step 3: Push your new code to AWS

We prefer to do this via our continuous integration server but you can do this with the simple command line:

git aws.push



Within a few minutes you should see 3 memory metrics available in Cloudwatch under Linux System

Otreva is a custom software product development company focusing on user experience, responsive web development, & mobile application development.

Interested in seeing what it costs to build an app?

Start Quote See Stats
224 Wyoming Ave. #100
Scranton, PA 18503

You've found the secret footer!

Tweets about @Otreva

Or check us out on:

Shopify Experts