How to get the EC2 instance ipaddress through aws cli

We can retrieve the ipaddress of EC2 instance using awscli.

To get the private ipaddress,

#aws ec2 describe-instances --instance-id ID --query 'Reservations[].Instances[].PrivateIpAddress' --output text

To get the public ipaddress,

#aws ec2 describe-instances --instance-id ID --query 'Reservations[].Instances[].PublicIpAddress' --output text

Where ID need to be replaced with the EC2 instance id.