Does the CLI have any commands that can be used to retrieve the _private IP_ of an EC2 instance given the instance ID ?
What if I provide a tag instead?
curl --silent http://169.254.169.254/latest/meta-data/public-ipv4
Please call any time:
Cell: +1-916-202-1600
Skype: EdwardMGoldberg
LinkedIn: http://lnkd.in/2yWrBZ
AWS:
http://www.aws-partner-directory.com/PartnerDirectory/PartnerDetail?Name=myCloudWatcher
Edward M. Goldberg
http://myCloudWatcher.com/
e.m.g.
On Tue, Oct 7, 2014 at 1:11 PM, ribonoous [email protected] wrote:
Does the CLI have any commands that can be used to retrieve the _private
IP_ of an AWS machine ?—
Reply to this email directly or view it on GitHub
https://github.com/aws/aws-cli/issues/934.
aws ec2 describe-instances --instance-id i-3f3f3f3f
if you have jq installed…
instance_id=aws ec2 describe-instances --instance-id i-3f3f3f3f| jq —raw-output .Reservations[].Instances[].PrivateIpAddress
On Oct 7, 2014, at 4:11 PM, ribonoous [email protected] wrote:
Does the CLI have any commands that can be used to retrieve the private IP of an AWS machine ?
—
Reply to this email directly or view it on GitHub.
Thanks @digitaljedi2 Your JQ solution worked
@ribonoous Also, you can use the --query
option to avoid having an additional dependency. aws ec2 describe-instances --instance-id i-12345 --query 'Reservations[].Instances[].PrivateIpAddress'
.
Adding on top @jamesls answer:
aws ec2 describe-instances --instance-id i-0329b8ad --query 'Reservations[].Instances[].PrivateIpAddress' | grep -vE '\[|\]' | awk -F'"' '{ print $2 }'
This way you end up with a clean output.
This way you end up with a clean output.
There's also an extra param you can pass to describe-instances
to accomplish the same thing:
aws ec2 describe-instances \
--instance-id i-0329b8ad \
--query 'Reservations[].Instances[].PrivateIpAddress' \
--output text
thy are all wrong... it seems the --instance.id is ignored and ALL instances are shown always
Most helpful comment
@ribonoous Also, you can use the
--query
option to avoid having an additional dependency.aws ec2 describe-instances --instance-id i-12345 --query 'Reservations[].Instances[].PrivateIpAddress'
.