Enumerating aws tags with aws cli

I thought I could add a tag for my AWS machines, for example

Key: backup Value: 00 04 * * *

and then from our management server use this to schedule snapshots of a volume at a specific time. So far, I am struggling with the jmespath file, and I seem to be unable to figure out the json path extraction syntax:

aws ec2 describe-instances --query 'Reservations[].Instances[].Tags[?Key==`Backup`]'
[
   [],
   [],
   [],
   [],
   [
       {
           "Value": "00 04 * * *",
           "Key": "Backup"
       }
   ],
   [],
   []
]

I could use some help to decide how to extract the following two values ​​if the Backup tag is defined for the instance.

InstanceId, backup key value

+4
source share
1 answer

, , , , "" "". ( )

aws ec2 describe-tags --query "Tags[*].{Backup:Value,InstanceId:ResourceId}" --filters "Name=resource-type, Values=instance" --filters "Name=key,Values=Backup" --output table 

( , json .)

+1

All Articles