Skip to content

Instantly share code, notes, and snippets.

@pahud
Created August 14, 2016 03:02
Show Gist options
  • Save pahud/06986f897622070a3f173818409f983a to your computer and use it in GitHub Desktop.
Save pahud/06986f897622070a3f173818409f983a 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