Last active
October 15, 2019 10:49
-
-
Save kwoods/a725c65a1be31ba4403a5bccdcd83627 to your computer and use it in GitHub Desktop.
Get EC2 Instance's Stack Name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}') | |
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
aws ec2 describe-instances \ | |
--instance-id $INSTANCE_ID \ | |
--query 'Reservations[*].Instances[*].Tags[?Key==`aws:cloudformation:stack-name`].Value' \ | |
--region $REGION \ | |
--output text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works like a charm 👍