Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

having trouble getting multiple filters to work #582

Closed
mwhooker opened this issue Jan 7, 2014 · 15 comments
Closed

having trouble getting multiple filters to work #582

mwhooker opened this issue Jan 7, 2014 · 15 comments
Labels
documentation This is a problem with documentation.

Comments

@mwhooker
Copy link

mwhooker commented Jan 7, 2014

I want to describe all instances that match two tags. Perhaps I don't have the syntax right, but I can't find it documented anywhere.

aws ec2 describe-instances --filters "Name=tag:Name,Values=xxx,Name=tag:env,Values=dev"

gives me all instances by tag:env, and ignores tag:Name

@ehammond
Copy link

ehammond commented Jan 7, 2014

Does it do what you want if you separate the two tags as distinct arguments to the filters option?

aws ec2 describe-instances --filters "Name=tag:Name,Values=xxx" "Name=tag:env,Values=dev"

I agree that it is a bit odd to pass multiple values to a single option in *nix commands, but it works for me.

@mwhooker
Copy link
Author

mwhooker commented Jan 7, 2014

@ehammond perfect, thanks!

I still think what is meant by "list" should be documented in the help

  --filters (list)
          A list of filters used to match properties for Instances. For a com-
          plete reference to the available filter keys for this operation, see
          the Amazon EC2 API reference .

       Shorthand Syntax:

            Key value pairs, where values are separated by commas.
          --filters Name=string1,Values=string1,string2

       JSON Syntax:

          [
            {
              "Name": "string",
              "Values": ["string", ...]
            }
            ...
          ]

perhaps instead of (list) it can say
--filters filter1[ filter2 ... filterN]

I realize this may be an implementation detail of whichever opt parser is used under the covers...

@tobiaspal
Copy link

Please note that even the example in the help is wrong. On the aws ec2 describe-images help the example is the following:

       To describe Windows AMIs from Amazon that are backed by Amazon EBS

       This  example describes Windows AMIs provided by Amazon that are backed by Amazon EBS.

       Command:

       aws ec2 describe-images --filters "Name=is-public,Values=true,Name=owner-alias,Values=amazon,Name=platform,Values=Windows,Name=root-device-type,Values=ebs"

The command doesn't do what's in the description. It took me several puzzled looks, and I found the solution only after I found this bug.

@jamesls
Copy link
Member

jamesls commented Apr 7, 2014

@tobiaspal This has been fixed here. This will go out in the next release.

Will look at updating the doc synopsis as well.

@jamesls
Copy link
Member

jamesls commented Aug 13, 2014

Doc synopsis has been updated now. Closing out issue.

@michaelxwang
Copy link

The following JSON format appear to work:

aws ec2 describe-tags --region "us-east-1" --filters '
[
  {
    "Name": "resource-id",
    "Values": ["<i-xxx>"]
  },
  {
    "Name": "tag:<MyTag>",
    "Values": ["<true>"] 
  }
]'

@michaelxwang
Copy link

aws ec2 describe-tags --region "us-east-1" --filters "Name=resource-id,Values=<i-xxx>,Name=tag:<MyTag>,Values=<true>"

also works but it appears to be OR relationship while the JSON format appears to be AND relationship between the two filters.

@manikolbe
Copy link

This is so confusing! Thank God I found this page!

@boltronics
Copy link

@michaelxwang I just noticed this too. That inconsistent behavior has got to be a bug...

@Selvaslm4
Copy link

List the all the Instances With all the Instances Details along with attached Volume Details it must include Volume Name, Volume, and Size

Using this command I can be able to list the volume details with instance id and volume size.

aws ec2 describe-volumes –-query "Volumes[*].[Attachments[0].VolumeId,AvailabilityZone,Attachments[0].InstanceId,Attachments[0].State,Size]" --output text > test.txt

But my query I have to consolidate the whole instance list its includes instance id, instance state, region, platform, key pair name along with attached volumes name, volume id, volume size and mount path name like /dev/sda1,

Please help me with this.

Using this command can be able to get the instance details but I need to single query to get all the details.

aws ec2 describe-instances --filters "Name=instance-state-name,Values=*" --query "Reservations[].Instances[].[Tags[?Key==Name]| [0].Value,InstanceId,State.Name,InstanceType,Placement.AvailabilityZone,PrivateIpAddress,VolumeInfo:BlockDeviceMappings" --output text > instances.txt

@Swolebrain
Copy link

In the particular case of querying a tag key and value, you can also do something like this:

aws ssm describe-instance-information --filters "Key=tag:Patch Group,Values=myPatchGroup" --region us-east-1

In that case, 'Patch Group' is a tag key.

@brettkennard
Copy link

brettkennard commented Apr 16, 2020

Did this formatting just change ?

I had script running successfully - all of a sudden it fails to filter with the OR statement here on the filter.

e.g.

ec2_id1lst1=$(aws ec2 describe-instances --region $region --filter "Name=tag:Name,Values=$ec2_name1upper,Name=tag:Name,Values=$ec2_name1lower" --query 'Reservations[].Instances[].[InstanceId]' --output text | sed '$!N;s/\n/ /')

Looks like the OR statement was changed to AND. Is there instruction somewhere on this change and how to use a different OR for the filter?

@MAHDTech
Copy link

Did this formatting just change ?

I had script running successfully - all of a sudden it fails to filter with the OR statement here on the filter.

e.g.

ec2_id1lst1=$(aws ec2 describe-instances --region $region --filter "Name=tag:Name,Values=$ec2_name1upper,Name=tag:Name,Values=$ec2_name1lower" --query 'Reservations[].Instances[].[InstanceId]' --output text | sed '$!N;s/\n/ /')

Looks like the OR statement was changed to AND. Is there instruction somewhere on this change and how to use a different OR for the filter?

I had a script fail recently as well, this below is currently working ...

  • Ubuntu Bionic AND AMD64
aws ec2 describe-images --owners 099720109477 --filters "Name=name,Values=*ubuntu*bionic*" "Name=architecture,Values=x86_64"
  • Ubuntu Bionic AND AMD64 OR ARM64
aws ec2 describe-images --owners 099720109477 --filters "Name=name,Values=*ubuntu*bionic*" "Name=architecture,Values=x86_64,arm64"

@aridastidar
Copy link

aridastidar commented Sep 1, 2021

multiple values can be used as a proxy for OR
aws ec2 describe-instances --filter "Name=tag:$TAG_NAME, Values=$VALUE,$OR_VALUE"

thoward-godaddy pushed a commit to thoward-godaddy/aws-cli that referenced this issue Feb 12, 2022
Currently, `sam validate` requires AWS Creds (due to the SAM Translator).
This commits adds the ability to pass in the credientials through a profile
that is configured through `aws configure`.
thoward-godaddy pushed a commit to thoward-godaddy/aws-cli that referenced this issue Feb 12, 2022
* fix: Functional tests must run on localhost to work in Windows (aws#552)

* fix: spacing typo in Log statement in start-lambda (aws#559)

* docs: Fix syntax highlighting in README.md (aws#561)

* docs: Change jest to mocha in Nodejs init README (aws#564)

* docs: Fix @mhart link in README (aws#562)

* docs(README): removed cloudtrail, added SNS to generate-event (aws#569)

* docs: Update repo name references (aws#577)

* feat(debugging): Fixing issues around debugging Golang functions. (aws#565)

* fix(init): Improve current init samples around docs and fixes (aws#558)

* docs(README): Update launch config to SAM CLI from SAM Local (aws#587)

* docs(README): Update sample code for calling Local Lambda Invoke (aws#584)

* refactor(init): renamed handler for camel case, moved callback call up (aws#586)

* chore: aws-lambda-java-core 1.1.0 -> 1.2.0 for java sam init (aws#578)

* feat(validate): Add profile and region options (aws#582)

Currently, `sam validate` requires AWS Creds (due to the SAM Translator).
This commits adds the ability to pass in the credientials through a profile
that is configured through `aws configure`.

* docs(README): Update README prerequisites to include awscli (aws#596)

* fix(start-lambda): Remove Content-Type Header check (aws#594)

* docs: Disambiguation "Amazon Kinesis" (aws#599)

* docs: Adding instructions for how to add pyenv to your PATH for Windows (aws#600)

* docs: Update README with small grammar fix (aws#601)

* fix: Update link in NodeJS package.json (aws#603)

* docs: Creating instructions for Windows users to install sam (aws#605)

* docs: Adding a note directing Windows users to use pipenv (aws#606)

* fix: Fix stringifying λ environment variables when using Python2 (aws#579)

* feat(generate-event): Added support for 50+ events (aws#612)

* feat(invoke): Add region parameter to all invoke related commands (aws#608)

* docs: Breaking up README into separate files to make it easier to read (aws#607)

* chore: Update JVM size params to match docker-lambda (aws#615)

* feat(invoke): Invoke Function Without Parameters through --no-event (aws#604)

* docs: Update advanced_usage.rst with clarification on --env-vars usage (aws#610)

* docs: Remove an extra word in the sam packaging command (aws#618)

* UX: Improves event names to reflect Lambda Event Sources (aws#619)

* docs: Fix git clone typo in installation docs (aws#630)

* docs(README): Callout go1.x runtime support (aws#631)

* docs(installation): Update sam --version command (aws#634)

* chore(0.6.0): SAM CLI Version bump (aws#635)
@queglay
Copy link

queglay commented May 29, 2022

What if you want to use multiple filters with an AND condition instead of OR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation.
Projects
None yet
Development

No branches or pull requests