Created
April 21, 2021 11:51
-
-
Save rswrz/0e91763a5f3fb69b61b63d3d7b18d72e to your computer and use it in GitHub Desktop.
Revisions
-
rswrz created this gist
Apr 21, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #!/bin/bash aws_search_resources() { # First argument has to be the JSON string json=${1:?} # All other arguments will be passed to aws cli # e.g.: --region eu-central-1 shift # Escape quotes in JSON string json=${json//\"/\\\"} # Remove \n (new lines) in JSON string json=${json//$'\n'/} # Template for search query query='{ "Type": "TAG_FILTERS_1_0", "Query": "__JSON__" }' # Insert JSON string into search query template query=${query/__JSON__/$json} # Execute aws cli # Docs: https://docs.aws.amazon.com/cli/latest/reference/resource-groups/search-resources.html aws resource-groups search-resources --resource-query "$query" "$@" } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ #!/bin/bash # Simple query aws_search_resources '{ "ResourceTypeFilters": [ "AWS::EC2::Instance" ], "TagFilters": [ { "Key": "Patch Group", "Values": [ "Dev" ] } ] }' # Query with additional aws cli arguments aws_search_resources '{ "ResourceTypeFilters": [ "AWS::EC2::Instance" ], "TagFilters": [ { "Key": "Patch Group", "Values": [ "Dev" ] } ] }' --max-items 7 --region eu-central-1