
Q-Bits: Formatting Output in the AWS CLI with Amazon Q Developer
The blog post explores how the Amazon Q Developer simplify working with the AWS Command Line Interface (CLI).
Welcome to another installment of Q-Bits, our regular series showcasing cool ways Amazon employees are leveraging Amazon Q Developer. Today, we're diving into how Q Developer can assist with Formatting Output in the AWS CLI.
1
# list ec2 instances with id, name, public and private ip address in a table
1
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value | [0], PublicIpAddress, PrivateIpAddress]' --output table
1
2
3
4
5
6
7
------------------------------------------------------------------------------
| DescribeInstances |
+----------------------+-------------------+----------------+----------------+
| i-xxxxxxxxxxxxxxxxx | EKS Worker Node | 35.173.xxx.xx | 172.31.8.xxx |
| i-yyyyyyyyyyyyyyyyy | Web Server 01 | 3.85.yyy.yyy | 172.31.27.yy |
| i-zzzzzzzzzzzzzzzzz | Model Hosting | None | 172.31.11.zz |
+----------------------+-------------------+----------------+----------------+
1
list ec2 instances with id, and instance type sorted by instance type as text
1
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,InstanceType]' --output text | sort -k2
1
2
3
i-zzzzzzzzzzzzzzzzz g5.8xlarge
i-yyyyyyyyyyyyyyyyy t2.micro
i-xxxxxxxxxxxxxxxxx t3.medium
1
# list the Name tag of ec2 instances that are tagged with Team=Marketing
1
aws ec2 describe-instances --filters Name=tag:Team,Values=Marketing --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value]' --output text
1
Web Server 01
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.