Skip to content

Instantly share code, notes, and snippets.

@gregtaylor99
Forked from pahud/ec2_self_tagging.sh
Created March 23, 2018 01:02
Show Gist options
  • Save gregtaylor99/ef6f4ae67af35325d04d5eeacac8abce to your computer and use it in GitHub Desktop.
Save gregtaylor99/ef6f4ae67af35325d04d5eeacac8abce to your computer and use it in GitHub Desktop.
EC2 tag itself on instance launch with UserData
#!/bin/bash
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
region=${az%%?}
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
aws ec2 create-tags --resources $instance_id --region $region --tags \
Key=foo,Value=bar \
Key=Name,Value=myname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment