使用特殊过滤器示例创建此策略。
ec2-without-gmail-in-tag.yml
policies:
- name: ec2-without-gmail-in-tag
description: |
Stop EC2 instances that do not have a tag or if the tag exists but doesnt have a specific value
resource: ec2
filters:
- or:
# check if tag is absent
- "tag:ABC": absent
# or check if tag does not contain @gmail.com using a negative lookahead
- type: value
key: "tag:ABC"
op: regex
value: '^((?!@gmail.com).)*$'
re
您可以使用 python 的模块测试此过滤器。
$ python
>>> import re
>>> regex = '^((?!@gmail.com).)*$'
>>> re.match(regex, 'Test if @gmail.com matches').group(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
>>> re.match(regex, 'Test if @gmail matches').group(0)
'Test if @gmail matches'