Score:0

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

184.72.83.182

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

54.174.85.61

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

{ "NetworkInterfaces": [] }

vn flag
`aws ec2 describe-network-interfaces --filters Name=addresses.private-ip-address,Values=184.72.83.182` will get you the ENI. Part of the ENi's output should include an instance ID, in `Attachment.InstanceId`, per the docs at https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-network-interfaces.html.
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.
mangohost

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.