AWS CLI Hacks: Difference between revisions

From Public wiki of Kevin P. Inscoe
Jump to navigation Jump to search
(Created page with "More on AWS CLI at https://aws.amazon.com/cli/ ==EC2 Inventory== <pre> # Print instance id, name tag (if set) and instance state by name in CSV format aws cli <profile-name>...")
 
Line 5: Line 5:
<pre>
<pre>
# Print instance id, name tag (if set) and instance state by name in CSV format
# Print instance id, name tag (if set) and instance state by name in CSV format
aws cli <profile-name> --output json --region us-east-1 ec2 describe-instances | \
$ aws cli <profile-name> --output json --region us-east-1 ec2 describe-instances | \
         jq -r '.Reservations[].Instances[] | (.Tags | from_entries) as $tags | [.InstanceId, $tags.Name?, .State.Name] | @csv'
         jq -r '.Reservations[].Instances[] | (.Tags | from_entries) as $tags | [.InstanceId, $tags.Name?, .State.Name] | @csv'
"i-0191a4dge87a52360","instance-b","stopped"
"i-0191a4dge87a52360","instance-b","stopped"
"i-1234567890abcdef0","instance-a","running"
"i-1234567890abcdef0","instance-a","running"
</pre>
</pre>

Revision as of 19:59, 13 April 2020

More on AWS CLI at https://aws.amazon.com/cli/

EC2 Inventory

# Print instance id, name tag (if set) and instance state by name in CSV format
$ aws cli <profile-name> --output json --region us-east-1 ec2 describe-instances | \
        jq -r '.Reservations[].Instances[] | (.Tags | from_entries) as $tags | [.InstanceId, $tags.Name?, .State.Name] | @csv'
"i-0191a4dge87a52360","instance-b","stopped"
"i-1234567890abcdef0","instance-a","running"