Skip to content

Instantly share code, notes, and snippets.

@kwoods
Last active October 15, 2019 10:49
Show Gist options
  • Save kwoods/a725c65a1be31ba4403a5bccdcd83627 to your computer and use it in GitHub Desktop.
Save kwoods/a725c65a1be31ba4403a5bccdcd83627 to your computer and use it in GitHub Desktop.
Get EC2 Instance's Stack Name
#!/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
@max-lobur
Copy link

works like a charm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment