When I first started to use AWS CLI, I felt overwhelmed, and I wondered how long it would take me to be familiar with the tool. Fast forward to many months later, I find the AWS CLI very pleasant to use. For example, there are same patterns and the CLI reference page online is quite useful.

Anyway, like many thing I’ve learned about Linux, I learned and could retain the information better with practice and document. So, I’m gonna just dump the commands that I need and learn here to help my future self should I need to find the same commands.

Here is the first one. Let’s say I have a known private IP of an EC2 instance on AWS as How could I find its instance ID using AWS CLI?

We can use ‘describe-instances’ API by filtering for instance that match the desired private IP. Optionally, we can use --query, the client side query, to display just the instance of the instance. Here is an example:

➜ aws ec2 describe-instances --filters "Name=private-ip-address,Values=" \
    --query 'Reservations[].Instances[].InstanceId'

To learn more about this API, check at the references below.