Skip to content

Instantly share code, notes, and snippets.

@bpluly
Last active November 24, 2023 18:13
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 bpluly/687c81258534539d8114bb5f34334aa3 to your computer and use it in GitHub Desktop.
Save bpluly/687c81258534539d8114bb5f34334aa3 to your computer and use it in GitHub Desktop.
AWS describe-instances when private dns name is the instance resource

The Instance metadata has two fields for PrivateDNSName one in the Instance struct and then within NetworkInterfaces[] within that struct. When resource names are used for the private dns field you have to filter for the field in the NetworkInterfaces list (generally the first one). For example, to get the InstanceID of an instance using the resource name dns:

aws ec2 describe-instances --filters "Name=network-interface.private-dns-name,Values=i-0c8489ec965617999.eu-west-2.compute.internal" --query "Reservations[0].Instances[0].{Instance:InstanceId}" { "Instance": "i-0c8489ec965617999" }

I use this when using rsync in Fabric 2 to be able to sync local config with a server, like the certs on a number of servers. Sure it could be parsed but the original idea was to use the HostName from the connection (ssh) to create another connection for the rsync.

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