All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-BulkyDeleteExpiredSnapshot

Last Updated:Sep 20, 2024

Template name

ACS-ECS-BulkyDeleteExpiredSnapshot

Execute Now

Template description

Deletes multiple expired snapshots at a time.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

expiredDays

The number of days that have elapsed after the snapshots expired.

Number

Yes

regionId

The region ID.

String

No

{{ ACS::RegionId }}

force

Specifies whether to forcibly delete the snapshots.

Boolean

No

False

snapshotName

The name field that is used to filter the snapshots.

String

No

tags

The tags of the snapshots.

Json

No

[]

rateControl

The rate control settings.

Json

No

{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10}

OOSAssumeRole

The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS).

String

No

""

Output parameters

Parameter

Description

Type

deletedSnapshotIds

List

Permission policy that is required to execute the template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DeleteSnapshot",
                "ecs:DescribeSnapshots"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

References

For more information, see ACS-ECS-BulkyDeleteExpiredSnapshot.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Bulky delete expired snapshot
  zh-cn: the description in Chinese
  name-en: ACS-ECS-BulkyDeleteExpiredSnapshot
  zh-cn: the description in Chinese
  categories:
    - data_backup
Parameters:
  regionId:
    Label:
      en: RegionId
      zh-cn: the description in Chinese
    Type: String
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  force:
    Label:
      en: Forced deletion of Snapshot
      zh-cn: the description in Chinese
    Type: Boolean
    Default: false
  expiredDays:
    Label:
      en: Snapshot Expiration Days
      zh-cn: the description in Chinese
    Type: Number
  snapshotName:
    Label:
      en: Name Field Used To Filter Snapshot
      zh-cn: the description in Chinese
    Type: String
    Default: " "
  tags:
    Label:
      en: Snapshot Tags
      zh-cn: the description in Chinese
    Type: Json
    AssociationProperty: Tags
    AssociationPropertyMetadata:
      ShowSystem: false
    Default: [ ]
  rateControl:
    Label:
      en: Rate Control
      zh-cn: the description in Chinese
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: the description in Chinese
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: describeSnapshots
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Get the snapshots
      zh-cn: the description in Chinese
    Properties:
      Service: ECS
      API: DescribeSnapshots
      Parameters:
        RegionId: '{{ regionId }}'
        Tags: '{{ tags }}'
        Filter2Key: CreationEndTime
        Filter2Value:
          'Fn::FormatUTCTime':
            - 'Fn::AddHour':
                - '{{ ACS::CurrentUTCTime }}'
                - "Fn::Eval":
                    - '-{{ expiredDays }}*24'
            - '%Y-%m-%dT00:00Z'
    Outputs:
      snapshotIds:
        Type: List
        ValueSelector: '.Snapshots.Snapshot[] | select( .SnapshotName | test("{{snapshotName}}")) | .SnapshotId'
  - Name: deleteSnapshots
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Delete the snapshots
      zh-cn: the description in Chinese
    Properties:
      Service: ECS
      API: DeleteSnapshot
      Parameters:
        RegionId: '{{ regionId }}'
        SnapshotId: '{{ ACS::TaskLoopItem }}'
        Force: '{{ force }}'
    Loop:
      Items: '{{ describeSnapshots.snapshotIds }}'
      RateControl: '{{ rateControl }}'
Outputs:
  deletedSnapshotIds:
    Type: List
    Value: '{{ describeSnapshots.snapshotIds }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - regionId
          - expiredDays
          - snapshotName
          - tags
          - force
        Label:
          default:
            zh-cn: the description in Chinese
            en: Configure Parameters
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: the description in Chinese
            en: Control Options