Monitor AWS Auto Scaling Activities with PowerShell

Recently, I needed to monitor my auto scaling groups in AWS, to see why they weren’t scaling up properly. Although I can use the AWS management console to monitor these activity messages, it isn’t very efficient to continuously click the refresh button. Hence, I wanted to automate the process of retrieving that data at the command line, specifically PowerShell, because it’s an object-based shell.

In the AWS.Tools.AutoScaling module, there’s a PowerShell command called Get-ASScalingActivity, which maps to the DescribeScalingActivities API call in AWS. This command returns all of the activities, for all auto scaling groups, in the current AWS region, or region that you specify with the -Region parameter.

You can install the Auto Scaling module with the command below.

Install-Module -Name AWS.Tools.AutoScaling -Scope CurrentUser -Force

Each of the “activities” that is returned by the Get-ASScalingActivity command has an array of useful properties, such as the start/end times, status code, auto scaling group name, and success/failure details. By default, the output is spit out in a verbose list format, containing all of these properties, which isn’t very human-readable.

This is the command I came up with, to monitor the latest messages from my Auto Scaling Groups.

Get-ASScalingActivity | Sort-Object -Property EndTime | Select-Object -Property EndTime, AutoScalingGroupName, StatusCode, StatusMessage, Cause -Last 50 | Format-Table -AutoSize

This gives me a nice, tabular, sorted array of insights into successful and failed scaling operations, so I can go troubleshoot accordingly. It limits the results to only the last 50 entries, which helps to ensure that you’re only looking at the newest, relevant activity results.

As you can see from the screenshot below, I hit my current limit for EC2 Spot Instances, of that particular instance type. Now I know that I need to contact AWS Support to raise the limit.

There are tons of other opportunities to use the AWS PowerShell module to automate activities that are normally painful to perform in the AWS Management Console! If you’re interested in getting started with the AWS PowerShell module, check out my training at CBT Nuggets.