Dragon Yoon
Dragon Yoon

Reputation: 33

How to get AWS subnet name from AWS CLI or EC2 metadata

I can get to the subnet id though not the subnet name, I don't see this in the metadata either...

I need to switch based the subnet name on a script, don't want to have ids mapped to logical names...

Wondering how/if I can get the subnet name somehow

Upvotes: 1

Views: 1564

Answers (1)

Erico
Erico

Reputation: 1471

If you can use the CLI you can use ec2 describe-subnets, like so:

aws ec2 describe-subnets --subnet-ids $SUBNET_ID --query "Subnets[*].Tags[?Key=='Name'].Value" --output text

Upvotes: 4

Related Questions