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.
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.
Currently AWS CLI doesn't provide support for UNIX wildcards in a command's “path” argument. However, it is quite easy to replicate this functionality using the --exclude and --include parameters available on several aws s3 commands.
This bash scripting example for Amazon EC2 changes the instance type for an Amazon EC2 instance using the AWS Command Line Interface (AWS CLI). It stops the instance if it's running, changes the instance type, and then, if requested, restarts the instance.
AWS support many ways to let you connect to your servers(EC2), we will introduce three methods : SSH, Instance Connect, System Manager and deep dive in EC2 Instance Connect and System Manager – Session Manager.
An ARN (Amazon Resource Name) uniquely identifies a resource. For more information, see Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces in the Amazon Web Services General Reference . Specifies a list of tags that you want to add to the specified resources.
Here is an example of how to filter the output of ec2-describe-instances
based on the value of a tag:
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*
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With