How to get instace id of aws ec2 from ip address?

ng flag

With below aws cli command, I can get public ip of the ec2 instance if the instance id is known.

aws ec2 describe-instances --instance-ids i-0d577af80725c9a91 --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile testsubaccount --region us-east-1

But, how to do the reverse?

I mean, when I know the public ip address, how to get the instace id of the ec2 instance?

aws ec2 describe-instances --instance-ids i-038317982dc6a7c64 --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile uday-subaccount --region us-east-1

aws ec2 describe-network-interfaces --filters Name=addresses.private-ip-address,Values= --profile uday-subaccount --region us-east-1

{ "NetworkInterfaces": [] }

vn flag
`aws ec2 describe-network-interfaces --filters Name=addresses.private-ip-address,Values=` will get you the ENI. Part of the ENi's output should include an instance ID, in `Attachment.InstanceId`, per the docs at
ng flag
the command I tried as you suggested but not giving any output. can you please check the details added above
vn flag
Do the `aws ec2 describe-network-interfaces` without the filters and see what's there, then start adding them back.

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.