操作标记操作在云托管中不起作用

问题描述 投票:0回答:1

我一直在设置云托管策略,以便在一段时间后自动终止 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
amazon-web-services amazon-ec2 cloud cloudcustodian
1个回答
0
投票

尽管已经提到了延迟操作的自定义标签,但您的政策看起来是正确的

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

那么你:

  • 通过标记资源将操作标记为未来的延迟操作
  • 使用“marked-for-op”过滤器类型过滤这些资源,并在您的操作中执行终止操作。

参考:https://www.cloudcustodian.io/docs/azure/examples/resourcegroupsdelayedoperation-general.html#azure-example-delayedoperation

© www.soinside.com 2019 - 2024. All rights reserved.