/count-ec2-instances

AWS Lambda Function to Count Number of Running EC2 Instances and Publish to Cloudwatch

Primary LanguageShell

count-ec2-instances

An AWS Lambda function to count the number of EC2 instances and publish to CloudWatch because why exactly can't I do that with CloudWatch out of the box?

Deployment

Assuming you have a ~/.aws/config with some pretty powerful permssions, you only need run make deploy. You'll most likely get tripped up on setting up IAM roles and permissions which you may not have permission to list/create/edit/etc. If you hit this problem, you may wish to create the CountEc2InstancesLambdaRole role manually applying the supplied role policy. You can then run make deployment-package.zip and ./create-or-update-function.sh

Functionality

It's pretty straight forward. Every five minutes we will query the EC2 API for instances in the running state and post the value to CloudWatch via the metric NumberRunningInstances.