Michael Martinez
Michael Martinez

Reputation: 2863

How to get the InstanceID using the PublicDnsName?

With the AWS CLI, given a PublicDnsName, how can I get the InstanceID? I tried

aws ec2 describe-instances --filters 'Name=publicdnsname,Values=ec2....

but it complains that

publicdnsname is not a valid filter

Upvotes: 1

Views: 530

Answers (2)

helloV
helloV

Reputation: 52433

It is dns-name

aws ec2 describe-instances --filters "Name=dns-name,Values=ec2-xxxxx.compute-1.amazonaws.com" --query 'Reservations[*].Instances[*].InstanceId' --output text

Output

i-00123458ca3fa2c4f

Upvotes: 1

Mark B
Mark B

Reputation: 201058

The valid filters are listed in the docs.

To filter by public DNS name the filter name you should use is: dns-name

Upvotes: 1

Related Questions