All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand

Last Updated:Dec 23, 2025

Template name

ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand - Uses a lifecycle hook to download an OSS file to an ECS instance and execute a command.

Execute Now

Template description

Uses a lifecycle hook to download an Object Storage Service (OSS) object to Elastic Compute Service (ECS) instances and run commands on the ECS instances.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

bucketName

The name of the OSS bucket.

String

Yes

objectName

The name of the OSS object.

String

Yes

destinationDir

Target directory for file copying on the instance

String

Yes

URLExpirationTime

The validity period of the download URL of the OSS object.

Number

No

6000

OSSRegion

The region in which the OSS bucket resides.

String

No

{{ ACS::RegionId }}

whetherSaveToFile

Specifies whether to save the file content to a specific file.

Boolean

No

True

commandContent

The Cloud Assistant commands to be run on the ECS instance.

String

No

echo hello

timeout

The timeout period for running the commands on the ECS instance.

Number

No

600

regionId

The region ID.

String

No

${regionId}

instanceIds

The IDs of the ECS instances.

List

No

['${instanceIds}']

lifecycleHookId

The lifecycle hook ID.

String

No

${lifecycleHookId}

lifecycleActionToken

The token of a specific scaling activity that is associated with the instances.

String

No

${lifecycleActionToken}

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

OOSServiceRole

Output parameters

None

Policy that is required to execute the template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "oss:GetObject"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "ecs:DescribeInstances",
                "ecs:DescribeInvocationResults",
                "ecs:DescribeInvocations",
                "ecs:RunCommand"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "ess:CompleteLifecycleAction"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

Details

ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Uses a lifecycle hook to download an OSS file to the ECS instance of a specified scaling activity and run a command.
  zh-cn: Uses a lifecycle hook to download an OSS file to the ECS instance of a specified scaling activity and run a command.
  name-en: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
  name-zh-cn: Uses a lifecycle hook to download an OSS file to an ECS instance and run a command.
  categories:
    - elastic_manage
Parameters:
  bucketName:
    Label:
      en: BucketName
      zh-cn: The name of the OSS bucket.
    Type: String
  objectName:
    Label:
      en: ObjectName
      zh-cn: The name of the OSS object.
    Type: String
  URLExpirationTime:
    Label:
      en: OSSFileDownloadURLExpirationTime
      zh-cn: The expiration time of the OSS file download URL.
    Description:
      en: The time-to-live (TTL), in seconds, for the download URL of the OSS object.
      zh-cn: The time-to-live (TTL), in seconds, for the download URL of the OSS object.
    Type: Number
    Default: 6000
  OSSRegion:
    Label:
      en: OSSRegion
      zh-cn: The region where the OSS bucket is located.
    Type: String
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  destinationDir:
    Label:
      en: DestinationDir
      zh-cn: The destination directory on the instance to which the file is copied.
    Type: String
  whetherSaveToFile:
    Label:
      en: whetherSaveToFile
      zh-cn: Specifies whether to download the content to a specific file.
    Type: Boolean
    Default: true
  commandContent:
    Label:
      en: CommandContent
      zh-cn: The Cloud Assistant command to run on the ECS instance.
    Type: String
    AssociationProperty: Code
    Default: echo hello
  timeout:
    Label:
      en: Timeout
      zh-cn: The timeout period for running the command on the ECS instance.
    Type: Number
    Default: 600
  regionId:
    Label:
      en: RegionId
      zh-cn: The region ID.
    Description:
      en: The ID of the region. Use the default value ${regionId} provided by Auto Scaling.
      zh-cn: The ID of the region. Use the default value ${regionId} provided by Auto Scaling.
    Type: String
    Default: '${regionId}'
  instanceIds:
    Label:
      en: InstanceIds
      zh-cn: A list of ECS instance IDs.
    Description:
      en: A list of ECS instance IDs. Use the default value ["${instanceId}"] provided by Auto Scaling.
      zh-cn: A list of ECS instance IDs. Use the default value ["${instanceId}"] provided by Auto Scaling.
    Type: List
    Default:
      - '${instanceIds}'
  lifecycleHookId:
    Label:
      en: LifecycleHookId
      zh-cn: The ID of the lifecycle hook.
    Description:
      en: The ID of the lifecycle hook. Use the default value ${lifecycleHookId} provided by Auto Scaling.
      zh-cn: The ID of the lifecycle hook. Use the default value ${lifecycleHookId} provided by Auto Scaling.
    Type: String
    Default: '${lifecycleHookId}'
  lifecycleActionToken:
    Label:
      en: LifecycleActionToken
      zh-cn: The token for the scaling activity that is associated with the instance.
    Description:
      en: The token for the scaling activity that is associated with the instance. Use the default value ${lifecycleActionToken} provided by Auto Scaling.
      zh-cn: The token for the scaling activity that is associated with the instance. Use the default value ${lifecycleActionToken} provided by Auto Scaling.
    Type: String
    Default: '${lifecycleActionToken}'
  rateControl:
    Label:
      en: RateControl
      zh-cn: Rate control.
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: The RAM role that OOS assumes.
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: downloadFileAndRunCommand
    OnError: CompleteLifecycleActionForAbandon
    OnSuccess: CompleteLifecycleActionForContinue
    Action: ACS::ECS::DownloadOSSFileAndRunCommand
    Description:
      en: Downloads a file to the ECS instances and runs a command.
      zh-cn: Downloads a file to the ECS instances and runs a command.
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
      bucketName: '{{ bucketName }}'
      objectName: '{{ objectName }}'
      URLExpirationTime: '{{ URLExpirationTime }}'
      OSSRegion: '{{ OSSRegion }}'
      destinationDir: '{{ destinationDir }}'
      whetherSaveToFile: '{{ whetherSaveToFile }}'
      commandContent: '{{ commandContent }}'
      timeout: '{{ timeout }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ instanceIds }}'
  - Name: CompleteLifecycleActionForContinue
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Changes the lifecycle action to Continue.
      zh-cn: Changes the lifecycle action to Continue.
    OnSuccess: 'ACS::END'
    Properties:
      Service: ESS
      API: CompleteLifecycleAction
      Parameters:
        RegionId: '{{ regionId }}'
        LifecycleHookId: '{{ lifecycleHookId }}'
        LifecycleActionToken: '{{ lifecycleActionToken }}'
        LifecycleActionResult: CONTINUE
  - Name: CompleteLifecycleActionForAbandon
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Changes the lifecycle action to Abandon.
      zh-cn: Changes the lifecycle action to Abandon.
    Properties:
      Service: ESS
      API: CompleteLifecycleAction
      Parameters:
        RegionId: '{{ regionId }}'
        LifecycleHookId: '{{ lifecycleHookId }}'
        LifecycleActionToken: '{{ lifecycleActionToken }}'
        LifecycleActionResult: ABANDON