Skip to content

Instantly share code, notes, and snippets.

@ianmas-aws
Last active August 29, 2015 13:56
Show Gist options
  • Save ianmas-aws/8840850 to your computer and use it in GitHub Desktop.
Save ianmas-aws/8840850 to your computer and use it in GitHub Desktop.
How use the command line to find out which tags are associated with an EC2 instance
Try this - it requires that you have the AWS command line tools installed and that your instance has either been assigned an IAM role with sufficent permissions, or that your AWS command line tools have been set up with the right credentials. You should use IAM roles if you want to get this info at first boot, which I suspect is what you want to use this for?
aws ec2 describe-instances --region eu-west-1 --output text --instance-ids `curl -s http://169.254.169.254/latest/meta-data/instance-id` | grep TAGS
If you create an IAM role called AllowDescribeInstances with the following policy this and assign it to your instances, this is the minimum permissions set that is required.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1391694313000",
"Effect": "Allow",
"Action": [
"ec2:DescribeInstances"
],
"Resource": [
"*"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment