Question:
I have some EC2 instances. I want to use the ec2 describe-instances
command to get a list of instances based on a specific value of a tag.
The table shows my use-case.
1 2 3 4 5 6 7 8 9 |
Instance | Value (key:Purpose) | Outcome ----------+-------------------------+------------ InstanceA | Going | Filter InstanceB | Shopping,Going | Filter InstanceC | Going,Shoping | Filter InstanceD | Shopping,Going,Chatting | Filter InstanceE | GoingGreat | DONT Filter InstanceF | NotGoing | DONT Filter |
So I want to somehow use wildcard in the ec2-describe-instances command so that I get the expected outcome.
Answer:
Here is an example of how to filter the output of ec2-describe-instances
based on the value of a tag:
1 2 |
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId]' --filters "Name=platform,Values=windows" --output text |
This example shows the Instance ID for all EC2 instance with the “platform” tag set to a value of “windows”.
Wildcards are also permitted in the Values parameter (eg Name=platform,Values=win*
).