Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use wildcards in `aws-cli ec2` commands?

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.

like image 405
Deep Avatar asked Dec 31 '14 10:12

Deep


People also ask

Can you use wildcard in AWS CLI?

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.

Which cli syntax is used to change an EC2 instance type?

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.

What are the 3 different methods that you connect to a EC2 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.

Which CLI command is used to tag aws resources?

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.


1 Answers

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*).

like image 165
John Rotenstein Avatar answered Oct 31 '22 16:10

John Rotenstein