Skip to content

Instantly share code, notes, and snippets.

@elocnatsirt
Last active Feb 9, 2017
Embed
What would you like to do?
Retrieves information about an AWS instance and outputs it via stdout. Written to use as a Sensu check to get basic information about a client.
#!/bin/bash
# Written By: https://github.com/elocnatsirt
# This script will curl the instance metadata and output useful values
# If the system isn't in AWS it will succeed with a relevant message
instance_id=`curl --silent http://169.254.169.254/latest/meta-data/instance-id`
instance_type=`curl --silent http://169.254.169.254/latest/meta-data/instance-type`
location=`curl --silent http://169.254.169.254/latest/meta-data/placement/availability-zone`
region=`curl --silent http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/.$//'`
if [ "$instance_id" == "" ]; then
echo "This is not an AWS instance"
exit 0
fi
echo "Location: ${location}"
echo "Instance ID: ${instance_id}"
echo "Instance Type: ${instance_type}"
echo "Cloudwatch Link: https://console.aws.amazon.com/cloudwatch/home?region=${region}#metrics:metricFilter=Search%253D${instance_id}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment