Skip to content

Instantly share code, notes, and snippets.

@SarahFrench
Forked from pahud/ec2_self_tagging.sh
Created May 29, 2024 15:24
Show Gist options
  • Save SarahFrench/a78cbf379eac1a508af009b956bcc69c to your computer and use it in GitHub Desktop.
Save SarahFrench/a78cbf379eac1a508af009b956bcc69c 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