user3299633
user3299633

Reputation: 3390

Use AWS CLI to pull in multiple information

Right now this following code segment will list the 'Name' tag of the resource of any instance that doesn't have a 'Grant' tag.

for region in `aws ec2 describe-regions --output text | cut -f3`
do
aws ec2 describe-instances \
   --region $region \
   --output text \
   --query 'Reservations[].Instances[?!not_null(Tags[?Key == `Grant`].Value)] | [].Tags[?Key==`Name`].Value'
done

I've tried a few ways to get the Public IP address but I keep getting errors for bad syntax.

Is it possible to pull in the Public IP here?

Upvotes: 0

Views: 164

Answers (1)

Amit Prajapati
Amit Prajapati

Reputation: 46

Yes, It is possible to pull the PublicIp address along with the Tags value. Replace query syntax as below,

    --query 'Reservations[].Instances[?!not_null(Tags[?Key == `Grant`].Value)] | [].[PublicIpAddress, Tags[?Key==`Name`].Value]'

Upvotes: 2

Related Questions