Download a file to ECS instances and run a command by using an Auto Scaling lifecycle hook.
Template name
ACS-ESS-LifeCycleDownloadFileAndRunCommand
Template description
Downloads a file to Elastic Compute Service (ECS) instances and runs a command on the instances by using a lifecycle hook.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
|
Parameter |
Description |
Type |
Required |
Default value |
Limit |
|
sourcePath |
The URL of the file to download. |
String |
Yes |
||
|
destinationDir |
The destination directory on the ECS instance. |
String |
Yes |
||
|
whetherSaveToFile |
Specifies whether to save the downloaded content to a file. |
Boolean |
No |
True |
|
|
commandContent |
The Cloud Assistant command to run on the ECS instance. |
String |
No |
echo hello |
|
|
timeout |
The timeout period for the command. |
Number |
No |
600 |
|
|
regionId |
The region ID. |
String |
No |
${regionId} |
|
|
instanceIds |
The IDs of the ECS instances. |
List |
No |
['${instanceIds}'] |
|
|
lifecycleHookId |
The ID of the lifecycle hook. |
String |
No |
${lifecycleHookId} |
|
|
lifecycleActionToken |
The token of the scaling activity associated with the instance. |
String |
No |
${lifecycleActionToken} |
|
|
rateControl |
The rate control settings. |
Json |
No |
{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} |
|
|
OOSAssumeRole |
The RAM role that is assumed by CloudOps Orchestration Service (OOS). |
String |
No |
OOSServiceRole |
Output parameters
None
Required permission policy
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ess:CompleteLifecycleAction"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-ESS-LifeCycleDownloadFileAndRunCommand.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Use lifecycleHook to download file and run command in the specified scaling activity instance
name-en: ACS-ESS-LifeCycleDownloadFileAndRunCommand
categories:
- elastic_manage
Parameters:
sourcePath:
Type: String
Label:
en: SourcePath
destinationDir:
Label:
en: DestinationDir
Type: String
whetherSaveToFile:
Label:
en: whetherSaveToFile
Type: Boolean
Default: true
commandContent:
Label:
en: CommandContent
Type: String
AssociationProperty: Code
Default: echo hello
timeout:
Label:
en: Timeout
Type: Number
Default: 600
regionId:
Label:
en: RegionId
Description:
en: The ID of region
Type: String
Default: '${regionId}'
instanceIds:
Label:
en: InstanceIds
Description:
en: The ID list of the ECS instance
Type: List
Default:
- '${instanceIds}'
lifecycleHookId:
Label:
en: LifecycleHookId
Description:
en: The ID of the lifecycle hook
Type: String
Default: '${lifecycleHookId}'
lifecycleActionToken:
Label:
en: LifecycleActionToken
Description:
en: The token that indicates a specific scaling activity associated with an instance
Type: String
Default: '${lifecycleActionToken}'
rateControl:
Label:
en: RateControl
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: downloadFileAndRunCommand
OnError: CompleteLifecycleActionForAbandon
OnSuccess: CompleteLifecycleActionForContinue
Action: ACS::ESS::DownloadFileAndRunCommand
Description:
en: Downloads file to the ECS instances adn run command
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
sourceType: https
sourcePath: '{{ sourcePath }}'
destinationDir: '{{ destinationDir }}'
whetherSaveToFile: '{{ whetherSaveToFile }}'
commandContent: '{{ commandContent }}'
timeout: '{{ timeout }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ instanceIds }}'
- Name: CompleteLifecycleActionForContinue
Action: 'ACS::ExecuteAPI'
Description:
en: Modify lifecycle action for 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: Complete lifecycle action for Abandon
Properties:
Service: ESS
API: CompleteLifecycleAction
Parameters:
RegionId: '{{ regionId }}'
LifecycleHookId: '{{ lifecycleHookId }}'
LifecycleActionToken: '{{ lifecycleActionToken }}'
LifecycleActionResult: ABANDON