ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand
模板名稱
ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand 通過下載OSS文件并執(zhí)行命令的方式滾動更新伸縮組內(nèi)的ECS實例
模板描述
通過下載OSS文件并執(zhí)行命令的方式滾動更新伸縮組內(nèi)的ECS實例
模板類型
自動化
所有者
Alibaba Cloud
輸入?yún)?shù)
參數(shù)名稱 | 描述 | 類型 | 是否必填 | 默認(rèn)值 | 約束 |
invokeType | 操作類型 | String | 是 | ||
scalingGroupId | 伸縮組ID | String | 是 | ||
invokeBucketName | 用于升級的Bucket名稱 | String | 是 | ||
invokeObjectName | 用于升級的Object名稱 | String | 是 | ||
invokeDestinationDir | 用于升級的文件存儲目錄 | String | 是 | ||
rollbackBucketName | 用于回滾的Bucket名稱 | String | 是 | ||
rollbackObjectName | 用于回滾的Object名稱 | String | 是 | ||
rollbackDestinationDir | 用于回滾的文件存儲目錄 | String | 是 | ||
enterProcess | 執(zhí)行開始要暫停的伸縮組流程 | List | 否 | ['ScaleIn', 'ScaleOut', 'HealthCheck', 'AlarmNotification', 'ScheduledAction'] | |
exitProcess | 執(zhí)行結(jié)束要恢復(fù)的伸縮組流程 | List | 否 | ['ScaleIn', 'ScaleOut', 'HealthCheck', 'AlarmNotification', 'ScheduledAction'] | |
invokeScript | 用于升級的腳本 | String | 否 | "" | |
rollbackScript | 用于回滾的腳本 | String | 否 | "" | |
sourceExecutionId | 用于回滾的OOS執(zhí)行ID | String | 否 | "" | |
whetherSaveToFile | 是否將內(nèi)容下載到特定文件 | Boolean | 否 | True | |
URLExpirationTime | OSS文件下載鏈接的過期時間 | Number | 否 | 6000 | |
OSSRegion | OSS所在地域 | String | 否 | {{ ACS::RegionId }} | |
batchPauseOption | 分批模式 | String | 否 | Automatic | |
batchNumber | 分批執(zhí)行的批次 | Number | 否 | 5 | |
OOSAssumeRole | OOS扮演的RAM角色 | String | 否 | "" |
輸出參數(shù)
參數(shù)名稱 | 描述 | 類型 |
commandOutputs | List |
執(zhí)行此模板需要的權(quán)限策略
{
"Version": "1",
"Statement": [
{
"Action": [
"ess:CreateLifecycleHook",
"ess:DescribeLifecycleHooks",
"ess:DescribeScalingInstances",
"ess:ModifyLifecycleHook",
"ess:ResumeProcesses",
"ess:SuspendProcesses"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oss:GetObject"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand",
"ecs:TagResources"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:ListExecutions"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳情
ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand詳情
模板內(nèi)容
FormatVersion: OOS-2019-06-01
Description:
en: Rolling update ECS instances that in scaling group by download OOS file and run command
zh-cn: 通過下載OSS文件并執(zhí)行命令的方式滾動更新伸縮組內(nèi)的ECS實例
name-en: ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand
name-zh-cn: 通過下載OSS文件并執(zhí)行命令的方式滾動更新伸縮組內(nèi)的ECS實例
categories:
- elastic_manage
Parameters:
invokeType:
Label:
en: InvokeType
zh-cn: 操作類型
Type: String
AllowedValues:
- invoke
- rollback
scalingGroupId:
Label:
en: ScalingGroupId
zh-cn: 伸縮組ID
Type: String
enterProcess:
Label:
en: EnterProcess
zh-cn: 執(zhí)行開始要暫停的伸縮組流程
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
exitProcess:
Label:
en: ExitProcess
zh-cn: 執(zhí)行結(jié)束要恢復(fù)的伸縮組流程
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
invokeBucketName:
Type: String
Label:
en: InvokeBucketName
zh-cn: 用于升級的Bucket名稱
invokeObjectName:
Label:
en: InvokeObjectName
zh-cn: 用于升級的Object名稱
Type: String
invokeDestinationDir:
Label:
en: InvokeDestinationDir
zh-cn: 用于升級的文件存儲目錄
Type: String
invokeScript:
Label:
en: InvokeScript
zh-cn: 用于升級的腳本
Type: String
AssociationProperty: Code
Default: ''
rollbackBucketName:
Type: String
Label:
en: RollbackBucketName
zh-cn: 用于回滾的Bucket名稱
rollbackObjectName:
Label:
en: RollbackObjectName
zh-cn: 用于回滾的Object名稱
Type: String
rollbackDestinationDir:
Label:
en: InvokeDestinationDir
zh-cn: 用于回滾的文件存儲目錄
Type: String
rollbackScript:
Label:
en: RollbackScript
zh-cn: 用于回滾的腳本
Type: String
AssociationProperty: Code
Default: ''
sourceExecutionId:
Label:
en: SourceExecutionId
zh-cn: 用于回滾的OOS執(zhí)行ID
Type: String
Default: ''
whetherSaveToFile:
Label:
en: whetherSaveToFile
zh-cn: 是否將內(nèi)容下載到特定文件
Type: Boolean
Default: true
URLExpirationTime:
Label:
en: OOSFileDownloadURLExpirationTime
zh-cn: OSS文件下載鏈接的過期時間
Type: Number
Default: 6000
OSSRegion:
Label:
en: OSSRegion
zh-cn: OSS所在地域
Description:
en: When the region where the OSS is located is different from the current region, the OSS file will be downloaded through the public network, and the ECS in the scaling group must be able to access the public network.
zh-cn: OSS所在地域和當(dāng)前地域不同時會通過公網(wǎng)下載OSS文件,需要伸縮組內(nèi)的ECS能訪問公網(wǎng)。
Type: String
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
batchPauseOption:
Label:
en: BatchPauseOption
zh-cn: 分批模式
Type: String
AllowedValues:
- Automatic
- FirstBatchPause
- EveryBatchPause
Default: Automatic
batchNumber:
Label:
en: BatchNumber
zh-cn: 分批執(zhí)行的批次
Type: Number
MinValue: 1
MaxValue: 100
Default: 5
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getLifecycleHook
Action: ACS::ExecuteAPI
Description:
en: Get lifecycle hook
zh-cn: 獲取生命周期掛鉤
Properties:
Service: ESS
API: DescribeLifecycleHooks
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
LifecycleHookName: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
Outputs:
totalCount:
Type: String
ValueSelector: .TotalCount
- Name: choiceNextTask
Action: 'ACS::Choice'
Description:
en: Choose next task by invoke type
zh-cn: 根據(jù)升級類型選擇任務(wù)
Properties:
DefaultTask: getInstance
Choices:
- When:
'Fn::Equals':
- rollback
- '{{ invokeType }}'
NextTask: getExecutionInstanceIds
- Name: getInstance
Description:
en: Views the ECS instances
zh-cn: 獲取ECS實例
Action: 'ACS::ExecuteApi'
Properties:
Service: ESS
API: DescribeScalingInstances
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
LifecycleState: InService
CreationTypes:
- AutoCreated
- Attached
Outputs:
instanceIds:
Type: List
ValueSelector: 'ScalingInstances.ScalingInstance[].InstanceId'
- Name: whetherTheScalingGroupInstanceIsEmpty
Action: 'ACS::Choice'
Description:
en: Check whether the instances in the services in the scaling group are empty
zh-cn: 檢查伸縮組內(nèi)服務(wù)中的實例是否為空
Properties:
DefaultTask: whetherToSuspendProcess
Choices:
- When:
'Fn::Equals':
- [ ]
- '{{ getInstance.instanceIds }}'
NextTask: 'ACS::END'
- Name: whetherToSuspendProcess
Action: 'ACS::Choice'
Description:
en: Choose next task by process
zh-cn: 根據(jù)流程值判斷是否暫停流程
Properties:
DefaultTask: suspendProcess
Choices:
- When:
'Fn::Equals':
- []
- '{{ enterProcess }}'
NextTask: invokeByDownloadOSSFileAndRunCommand
- Name: suspendProcess
Action: 'ACS::ExecuteAPI'
Description:
en: Suspend process
zh-cn: 暫停伸縮組流程
Properties:
Service: ESS
API: SuspendProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ enterProcess }}'
- Name: invokeByDownloadOSSFileAndRunCommand
Action: ACS::ECS::DownloadOSSFileAndRunCommand
Description:
en: Upgrade by downloading files to the instance and executing commands
zh-cn: 通過下載文件到實例并執(zhí)行命令的方式進(jìn)行升級
Properties:
instanceId: '{{ ACS::TaskLoopItem }}'
bucketName: '{{ invokeBucketName }}'
objectName: '{{ invokeObjectName }}'
URLExpirationTime: '{{ URLExpirationTime }}'
OSSRegion: '{{ OSSRegion }}'
commandContent: '{{ invokeScript }}'
destinationDir: '{{ invokeDestinationDir }}'
whetherSaveToFile: '{{ whetherSaveToFile }}'
Loop:
Items: '{{ getInstance.instanceIds }}'
BatchPauseOption: '{{ batchPauseOption }}'
Concurrency:
'Fn::CalculateBatch':
- '{{ batchNumber }}'
- '{{ getInstance.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: runCommandOutput
- Name: tagInstance
Action: ACS::ExecuteApi
Description:
en: Creates and attaches tag to ECS instance
zh-cn: 創(chuàng)建并掛載標(biāo)簽到ECS實例
Properties:
Service: ECS
API: TagResources
Parameters:
ResourceIds:
- '{{ ACS::TaskLoopItem }}'
ResourceType: Instance
Tags:
- Key: 'ess:rollingupdate'
Value: 'oos:{{ ACS::ExecutionId }}'
Loop:
Items: '{{ getInstance.instanceIds }}'
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
- Name: createLifecycleHookOfUpgrade
When:
Fn::Equals:
- '{{ getLifecycleHook.totalCount }}'
- 0
Action: ACS::ExecuteAPI
Description:
en: Create lifecycle hook of upgrade
zh-cn: 創(chuàng)建用于升級的生命周期掛鉤
Properties:
Service: ESS
API: CreateLifecycleHook
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
NotificationMetadata: '{"bucketName":"{{ invokeBucketName }}","objectName":"{{ invokeObjectName }}","URLExpirationTime":"{{ URLExpirationTime }}","OSSRegion":"{{ OSSRegion }}","destinationDir":"{{ invokeDestinationDir }}","OSSRegion":"{{ OSSRegion }}","commandContent":"{{ invokeScript }}","timeout":"600","regionId":"${regionId}","instanceIds":"${instanceIds}","lifecycleHookId":"${lifecycleHookId}","lifecycleActionToken":"${lifecycleActionToken}","rateControl":"{\"Mode\":\"Concurrency\",\"MaxErrors\":0,\"Concurrency\":10}","OOSAssumeRole":"OOSServiceRole"}'
LifecycleTransition: SCALE_OUT
LifecycleHookName: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
NotificationArn: acs:oos:{{ ACS::RegionId }}:{{ACS::AccountId}}:template/ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
- Name: modifyLifecycleHookOfUpgrade
When:
Fn::Equals:
- '{{ getLifecycleHook.totalCount }}'
- 1
Action: ACS::ExecuteAPI
Description:
en: Modify lifecycle hook of upgrade
zh-cn: 修改用于升級的生命周期掛鉤
Properties:
Service: ESS
API: ModifyLifecycleHook
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
NotificationMetadata: '{"bucketName":"{{ invokeBucketName }}","objectName":"{{ invokeObjectName }}","URLExpirationTime":"{{ URLExpirationTime }}","OSSRegion":"{{ OSSRegion }}","destinationDir":"{{ invokeDestinationDir }}","commandContent":"{{ invokeScript }}","timeout":"600","regionId":"${regionId}","instanceIds":"${instanceIds}","lifecycleHookId":"${lifecycleHookId}","lifecycleActionToken":"${lifecycleActionToken}","rateControl":"{\"Mode\":\"Concurrency\",\"MaxErrors\":0,\"Concurrency\":10}","OOSAssumeRole":"OOSServiceRole"}'
LifecycleTransition: SCALE_OUT
LifecycleHookName: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
- Name: whetherToResumeProcesses
Action: 'ACS::Choice'
Description:
en: Choose next task by process
zh-cn: 根據(jù)流程值判斷是否恢復(fù)流程
Properties:
DefaultTask: resumeProcesses
Choices:
- When:
'Fn::Equals':
- []
- '{{ exitProcess }}'
NextTask: 'ACS::END'
- Name: resumeProcesses
Action: 'ACS::ExecuteAPI'
OnSuccess: 'ACS::END'
Description:
en: Resume process
zh-cn: 恢復(fù)伸縮組流程
Properties:
Service: ESS
API: ResumeProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ exitProcess }}'
- Name: getExecutionInstanceIds
Action: 'ACS::ExecuteAPI'
Description:
en: Get the instance that has been executed
zh-cn: 獲取已經(jīng)執(zhí)行過執(zhí)行腳本的實例
Properties:
Service: OOS
API: ListExecutions
Parameters:
ParentExecutionId: '{{ sourceExecutionId }}'
Outputs:
instanceIds:
Type: List
ValueSelector: 'Executions[].Parameters.instanceId'
- Name: getExistInstanceIds
Description:
en: Views the ECS instances
zh-cn: 獲取ECS實例
Action: ACS::SelectTargets
Properties:
ResourceType: ALIYUN::ECS::Instance
Filters:
- Type: ResourceIds
ResourceIds: '{{ getExecutionInstanceIds.instanceIds }}'
Outputs:
instanceIds:
Type: List
ValueSelector: Instances.Instance[].InstanceId
- Name: getRollbackProcess
Action: 'ACS::ExecuteAPI'
Description:
en: Views resource parameters
zh-cn: 獲取源執(zhí)行的參數(shù)
Properties:
Service: OOS
API: ListExecutions
Parameters:
ExecutionId: '{{ sourceExecutionId }}'
Outputs:
enterProcess:
Type: List
ValueSelector: 'Executions[].Parameters.enterProcess[]'
exitProcess:
Type: List
ValueSelector: 'Executions[].Parameters.exitProcess[]'
- Name: suspendProcessWithRollBack
Action: 'ACS::ExecuteAPI'
Description:
en: Suspend process
zh-cn: 暫停伸縮組流程
Properties:
Service: ESS
API: SuspendProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ getRollbackProcess.enterProcess }}'
- Name: rollbackByDownloadOSSFileAndRunCommand
Action: ACS::ECS::DownloadOSSFileAndRunCommand
Description:
en: Rollback by downloading files to the instance and executing commands
zh-cn: 通過下載文件到實例并執(zhí)行命令的方式進(jìn)行回滾
Properties:
instanceId: '{{ ACS::TaskLoopItem }}'
bucketName: '{{ rollbackBucketName }}'
objectName: '{{ rollbackObjectName }}'
URLExpirationTime: '{{ URLExpirationTime }}'
OSSRegion: '{{ OSSRegion }}'
commandContent: '{{ rollbackScript }}'
destinationDir: '{{ rollbackDestinationDir }}'
whetherSaveToFile: '{{ whetherSaveToFile }}'
Loop:
Items: '{{ getExistInstanceIds.instanceIds }}'
BatchPauseOption: '{{ batchPauseOption }}'
Concurrency:
'Fn::CalculateBatch':
- '{{ batchNumber }}'
- '{{ getExistInstanceIds.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: runCommandOutput
- Name: modifyLifecycleHookOfRollback
When:
Fn::Equals:
- '{{ getLifecycleHook.totalCount }}'
- 1
Action: ACS::ExecuteAPI
Description:
en: Modify lifecycle hook of rollback
zh-cn: 修改用于回滾的生命周期掛鉤
Properties:
Service: ESS
API: ModifyLifecycleHook
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
NotificationMetadata: '{"bucketName":"{{ rollbackBucketName }}","objectName":"{{ rollbackObjectName }}","URLExpirationTime":"{{ URLExpirationTime }}","OSSRegion":"{{ OSSRegion }}","destinationDir":"{{ rollbackDestinationDir }}","commandContent":"{{ rollbackScript }}","timeout":"600","regionId":"${regionId}","instanceIds":"${instanceIds}","lifecycleHookId":"${lifecycleHookId}","lifecycleActionToken":"${lifecycleActionToken}","rateControl":"{\"Mode\":\"Concurrency\",\"MaxErrors\":0,\"Concurrency\":10}","OOSAssumeRole":"OOSServiceRole"}'
LifecycleTransition: SCALE_OUT
LifecycleHookName: ACS-ESS-LifeCycleDownloadOSSFileAndRunCommand
- Name: whetherToResumeProcessesWithRollback
Action: 'ACS::Choice'
Description:
en: Choose next task by process
zh-cn: 根據(jù)流程值判斷是否恢復(fù)流程
Properties:
DefaultTask: resumeProcessesWithRollback
Choices:
- When:
'Fn::Equals':
- []
- '{{ getRollbackProcess.exitProcess }}'
NextTask: 'ACS::END'
- Name: resumeProcessesWithRollback
Action: 'ACS::ExecuteAPI'
Description:
en: Resume process
zh-cn: 恢復(fù)伸縮組流程
Properties:
Service: ESS
API: ResumeProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ getRollbackProcess.exitProcess }}'
Outputs:
commandOutputs:
Type: List
Value:
'Fn::If':
- 'Fn::Equals':
- invoke
- '{{ invokeType }}'
- '{{ invokeByDownloadOSSFileAndRunCommand.commandOutputs }}'
- '{{ rollbackByDownloadOSSFileAndRunCommand.commandOutputs }}'