Is it possible to use AWS Account ID and Region in a filter? #8727
-
I would like to use the AWS Account ID and/or Region in a filter. I am building some alerts on CloudWatch metrics but the resources returned by CloudCustodian don't contain those identififers, there's no ARN because I assume CloudWatch metrics don't have an ARN. Example resources:
With the above resource information there is no way to filter on AWS Account ID and Region. With other resources (e.g. Lambda, S3, DynamoDB etc) those contain an ARN which allows for unique identification across accounts and regions via the ARN. I don't think the I would want to do something like:
(I am aware the pseudo code above for the key is incorrect). Is there a way to access the overall policy metadata (account ID, region etc) from within a filter? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Sure, you can do that. If you were looking for a filter named key: join('-', ['{account_id}', '{region}', filterName])
key: join('', ['{account_id}-{region}-', filterName]) And then you could check your matches against a list of known account/region/filterName combinations: filters:
- type: value
key: join('-', ['{account_id}', '{region}', filterName])
op: in
value:
- '111111111111-us-east-1-my-filter-1'
- '111111111111-us-east-2-my-filter-1'
- '111111111111-us-east-2-my-filter-2'
- '222222222222-us-west-2-my-filter-62' ...and from there, use |
Beta Was this translation helpful? Give feedback.
-
Perfect answer, tested and working, thanks. |
Beta Was this translation helpful? Give feedback.
Sure, you can do that. If you were looking for a filter named
my-filter-1
inus-east-2
of account111111111111
, you could use thekey
of your value filter to mush those elements into a single string. Your pseudocode was headed in the right direction and pretty close! A couple variations on an approach to do that:And then you could check your matches against a list of known account/region/filterName combinations: