Skip to content

Instantly share code, notes, and snippets.

@brb
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brb/1c0823e49113b4478e8f to your computer and use it in GitHub Desktop.
Save brb/1c0823e49113b4478e8f to your computer and use it in GitHub Desktop.
poor man's Elastic IP
#!/bin/bash
# Update /etc/hosts with public non-elastic IPs of EC2 instances.
# Assumes that a name is set for each instance and there is only one value inside tags section.
PREFIX="aws_"
FILTER=".Reservations[].Instances[] |
select(.PublicIpAddress != null) |
.PublicIpAddress + \" $PREFIX\" + .Tags[].Value"
sudo sed -i "/$PREFIX/d" /etc/hosts
aws ec2 describe-instances | jq -r "$FILTER" | sudo tee -a /etc/hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment