我一直在设置云托管策略,以便在一段时间后自动终止 ec2 实例。但不幸的是它不能正常工作。 过滤器和 mod 在策略中工作正常,但操作未执行。如果您有任何解决方案,请告诉我们。
Policy:
policies:
- name: ec2-terminate-instance
resource: ec2
description: |
Mark any stopped ec2 instance for deletion in 60 days
If an instance has not been started for 60 days or over
then they will be deleted similar to internal policies as it wont be patched.
filters:
- "tag:expiration": present
- "State.Name": stopped
mode:
schedule: "rate(15 minutes)"
type: periodic
role: arn:aws:iam::xxxxxxxxxxxx:role/cloud-custodian-role
actions:
- type: mark-for-op
tag: c7n_stopped_instance
op: terminate
hours: 0.5
尽管已经提到了延迟操作的自定义标签,但您的政策看起来是正确的
mark-for-op
。
这里的细节很重要,如果您没有看到使用此策略终止的实例,那是因为您需要第二个后续策略来过滤标记的资源以及终止这些发现的实例的相应操作。
- name: ec2-terminate-instance
resource: aws.ec2
description: |
Delete any marked instances in the previous policy based on the tag c7n_stopped_instance
filters:
- type: marked-for-op
tag: c7n_stopped_instance
op: terminate
actions:
- type: terminate
那么你: