Run commands on ECS instances through Auto Scaling lifecycle hooks.
Template name
ACS-ESS-LifeCycleRunCommand executes a command on an instance using a lifecycle hook.
Template description
Uses a lifecycle hook to run commands on Elastic Compute Service (ECS) instances.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
|
Parameter |
Description |
Type |
Required |
Default value |
Limit |
|
commandType |
The type of the Cloud Assistant commands. |
String |
No |
RunShellScript |
|
|
commandContent |
The content of the Cloud Assistant commands. |
String |
No |
echo hello |
|
|
timeout |
The timeout period in seconds. |
Number |
No |
600 |
|
|
lifecycleActionResult |
Subsequent action after the lifecycle hook wait state ends |
String |
No |
ABANDON |
|
|
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 for a specific scaling activity associated with the instances. |
String |
No |
${lifecycleActionToken} |
|
|
rateControl |
The rate control settings. |
Json |
No |
{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} |
|
|
OOSAssumeRole |
The RAM role assumed by CloudOps Orchestration Service (OOS). |
String |
No |
OOSServiceRole |
Output parameters
|
Parameter |
Description |
Type |
|
commandOutputs |
List |
Policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ess:CompleteLifecycleAction"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Details
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Uses a lifecycle hook to run a command on an instance in a specified scaling activity.
zh-cn: Uses a lifecycle hook to run a command on an instance in a specified scaling activity.
name-en: ACS-ESS-LifeCycleRunCommand
name-zh-cn: Use a lifecycle hook to run a command in an instance
categories:
- elastic_manage
Parameters:
commandType:
Label:
en: CommandType
zh-cn: Command type
Type: String
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
commandContent:
Label:
en: CommandContent
zh-cn: Command content
Type: String
AssociationProperty: Code
Default: echo hello
timeout:
Label:
en: Timeout (s)
zh-cn: Timeout (s)
Type: Number
Default: 600
lifecycleActionResult:
Label:
en: LifecycleActionResult
zh-cn: Next action after wait state ends
Description:
en: The next action to perform after the wait state ends if the command fails.
zh-cn: The next action to perform after the wait state ends if the command fails.
Type: String
AllowedValues:
- ABANDON
- ROLLBACK
- CONTINUE
Default: ABANDON
regionId:
Label:
en: RegionId
zh-cn: Region ID
Description:
en: The ID of the region. Use the Auto Scaling default value: ${regionId}
zh-cn: The ID of the region. Use the Auto Scaling default value: ${regionId}
Type: String
Default: '${regionId}'
instanceIds:
Label:
en: InstanceIds
zh-cn: List of ECS instance IDs
Description:
en: The list of ECS instance IDs. Use the Auto Scaling default value: ["${instanceId}"]
zh-cn: The list of ECS instance IDs. Use the Auto Scaling default value: ["${instanceId}"]
Type: List
Default:
- '${instanceIds}'
lifecycleHookId:
Label:
en: LifecycleHookId
zh-cn: Lifecycle hook ID
Description:
en: The ID of the lifecycle hook. Use the Auto Scaling default value: ${lifecycleHookId}
zh-cn: The ID of the lifecycle hook. Use the Auto Scaling default value: ${lifecycleHookId}
Type: String
Default: '${lifecycleHookId}'
lifecycleActionToken:
Label:
en: LifecycleActionToken
zh-cn: Token for a specific scaling activity
Description:
en: The token for the specific scaling activity associated with an instance. Use the Auto Scaling default value: ${lifecycleActionToken}
zh-cn: The token for the specific scaling activity associated with an instance. Use the Auto Scaling default value: ${lifecycleActionToken}
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: RAM role assumed by OOS
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: runCommand
Action: ACS::ECS::RunCommand
OnError: CompleteLifecycleActionForAbandon
OnSuccess: CompleteLifecycleActionForContinue
Description:
en: Executes a Cloud Assistant command.
zh-cn: Executes a Cloud Assistant command.
Properties:
regionId: '{{ regionId }}'
commandContent: '{{ commandContent }}'
instanceId: '{{ ACS::TaskLoopItem }}'
commandType: '{{ commandType }}'
timeout: '{{ timeout }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ instanceIds }}'
Outputs:
commandOutputs:
AggregateType: Fn::ListJoin
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
- Name: CompleteLifecycleActionForContinue
Action: 'ACS::ExecuteAPI'
Description:
en: Changes the wait state of the scaling activity to CONTINUE.
zh-cn: Changes the wait state of the scaling activity 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: Ends the lifecycle action with the specified result on failure.
zh-cn: Ends the lifecycle action with the specified result on failure.
Properties:
Service: ESS
API: CompleteLifecycleAction
Parameters:
RegionId: '{{ regionId }}'
LifecycleHookId: '{{ lifecycleHookId }}'
LifecycleActionToken: '{{ lifecycleActionToken }}'
LifecycleActionResult: '{{ lifecycleActionResult }}'
Outputs:
commandOutputs:
Type: List
Value: '{{ runCommand.commandOutputs }}'