My EC2 instance has many tags with a desired value EBM. The thing that this value could be in a different Name, sometimes under tag:Name and sometimes tag:XXX, I tried the below query and it didn’t work:
aws --region sa-east-1 ec2 describe-security-groups --filters 'Name=*,Values=*EBM*'
An error occurred (InvalidParameterValue) when calling the DescribeSecurityGroups operation: The filter ‘*’ is invalid
any idea how to make the Name as wild card just match the value?
I tried this and it didn’t work:
aws --region sa-east-1 ec2 describe-security-groups --filters 'Name=*,Values=*EBM*'
An error occurred (InvalidParameterValue) when calling the DescribeSecurityGroups operation: The filter ‘*’ is invalid
I also tried this and didn’t work:
aws --region sa-east-1 ec2 describe-security-groups --filters 'Name=*.*,Values=*EBM*'
2
Answers
Its not possible. You have to get all rules first, then then do filtering yourself.
Latest Edit:
I have tested that in my lab environment and its possible to get what you are looking for combining
--filter
&-query
altogether!Alternatively, you can use the
contains
function with theTag[]
in the query to match tag values that containSecGrp
anywhere in thevalue
, Keep in mind that the--query
option uses the JMESPath query language, which has its own syntax and rules. You can find more information on using JMESPath queries in the AWS CLI documentation.Further, to get the tag values for security groups in a hash form (i.e., a dictionary or associative array), you can combine that with your
--query
to get a nicer readable format, below is how you can get that …You can get into into tablular form as well..
Use
describe-tags
To
--filter
with a value only regardless of the name in the AWS CLI, you simply can use"Name=value,Values=*tg*"
.Name=value
so as to look at the value fields only.Value=*EBM*
it will fetch all values havingEBM
regardless of prefix or suffix.However, You can combine
--filters
with the--query
option to filter the output and only display specific fields. For example, to only display thetag
names andvalues
, you can use the following command:OR
You can get it as a table to be more readable ..
To make it more explicit before you use above, you can use the following command to be more simplistic. it will return all tags with a value of "VALUE", regardless of the tag name.:
If you want to filter the results further, you can include additional filters by adding them to the list in the –filters flag, separated by a comma. For example, to only return tags with a value of "VALUE" that are associated with security groups, you can use the following command:
EDIT:
Using
describe-security-groups
with all values*SecGrpec2*
and then get the name of Security group these value belongs to.