Nama templat
Melakukan pembaruan bergulir (rolling update) pada instance ECS dalam grup penskalaan dengan menjalankan perintah.
Deskripsi templat
Melakukan pembaruan bergulir (rolling update) pada instance ECS dalam grup penskalaan dengan menjalankan perintah.
Jenis templat
automation
Pemilik
Alibaba Cloud
Parameter input
|
Parameter |
Deskripsi |
Tipe |
Wajib |
Bawaan |
Batasan |
|
invokeType |
Jenis operasi. Atur ke |
String |
Ya |
||
|
scalingGroupId |
ID grup penskalaan yang berisi instance ECS target. |
String |
Ya |
||
|
enterProcess |
Proses grup penskalaan yang akan dihentikan sementara sebelum pembaruan dimulai. Menghentikan proses ini mencegah Auto Scaling mengganggu pembaruan. |
List |
Tidak |
|
|
|
exitProcess |
Proses grup penskalaan yang akan dilanjutkan setelah pembaruan selesai. Biasanya sama dengan |
List |
Tidak |
|
|
|
lifecycleState |
Status siklus hidup instance target. Tentukan |
List |
Tidak |
InService |
|
|
commandType |
Jenis skrip yang akan dijalankan. Nilai yang valid: |
String |
Tidak |
RunShellScript |
|
|
invokeScript |
Skrip pembaruan yang dijalankan pada setiap instans, seperti skrip shell yang menarik kode aplikasi terbaru dan memulai ulang layanan. |
String |
Tidak |
"" |
|
|
rollbackScript |
Skrip rollback yang dijalankan pada setiap instans. Skrip ini harus membatalkan perubahan yang dilakukan oleh |
String |
Tidak |
"" |
|
|
sourceExecutionId |
ID eksekusi OOS asli yang akan di-rollback. Diperlukan hanya ketika |
String |
Tidak |
"" |
|
|
batchPauseOption |
Kebijakan jeda antar batch. |
String |
Tidak |
Automatic |
|
|
batchNumber |
Jumlah batch untuk membagi instance. Misalnya, jika Anda memiliki 10 instance dan mengatur nilai ini ke |
Number |
Tidak |
5 |
|
|
OOSAssumeRole |
Peran RAM yang diasumsikan oleh OOS untuk melakukan pembaruan. Jika tidak ditentukan, OOS menggunakan izin pengguna saat ini. |
String |
Tidak |
"" |
Parameter Output
|
Parameter |
Deskripsi |
Tipe |
|
commandOutputs |
Output perintah dari setiap instans, sesuai dengan operasi yang ditentukan oleh |
List |
Kebijakan izin yang diperlukan
{
"Version": "1",
"Statement": [
{
"Action": [
"ess:DescribeScalingInstances",
"ess:EnterStandby",
"ess:ExitStandBy",
"ess:ResumeProcesses",
"ess:SetInstancesProtection",
"ess:SuspendProcesses"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand",
"ecs:TagResources"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:ListExecutions"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Detail
Detail ACS-ESS-RollingUpdateByRunCommandInScalingGroup
Konten Templat
FormatVersion: OOS-2019-06-01
Description:
en: Performs a rolling update on ECS instances in a scaling group by executing a command.
zh-cn: 通过执行命令的方式滚动更新伸缩组内的ECS实例
name-en: Perform Rolling Update in Scaling Group by Running Command
name-zh-cn: 通过执行命令的方式滚动更新伸缩组内的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: 执行开始要暂停的伸缩组流程
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
exitProcess:
Label:
en: ExitProcess
zh-cn: 执行结束要恢复的伸缩组流程
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
lifecycleState:
Label:
en: LifecycleState
zh-cn: 生命周期状态
Description:
en: The lifecycle state of the target ECS instance.
zh-cn: 要升级的ECS实例所处的生命周期状态
Type: List
AllowedValues:
- InService
- Protected
Default: InService
commandType:
Label:
en: CommandType
zh-cn: 命令类型
Type: String
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
invokeScript:
Label:
en: InvokeScript
zh-cn: 用于执行的脚本
Type: String
Default: ''
rollbackScript:
Label:
en: RollbackScript
zh-cn: 用于回滚的脚本
Type: String
Default: ''
sourceExecutionId:
Label:
en: SourceExecutionId
zh-cn: 用于回滚的OOS执行ID
Type: String
Default: ''
batchPauseOption:
Label:
en: BatchPauseOption
zh-cn: 分批模式
Type: String
AllowedValues:
- Automatic
- FirstBatchPause
- EveryBatchPause
Default: Automatic
batchNumber:
Label:
en: BatchNumber
zh-cn: 分批执行的批次
Type: Number
MinValue: 1
MaxValue: 100
Default: 5
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: choiceNextTask
Action: 'ACS::Choice'
Description:
en: Selects the next task based on the value of invokeType.
zh-cn: 根据执行类型选择任务
Properties:
DefaultTask: getInstance
Choices:
- When:
'Fn::Equals':
- rollback
- '{{ invokeType }}'
NextTask: getExecutionInstanceIds
- Name: getInstance
Description:
en: Retrieves the ECS instances in the scaling group.
zh-cn: 获取ECS实例
Action: 'ACS::ExecuteApi'
Properties:
Service: ESS
API: DescribeScalingInstances
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
LifecycleStates: '{{ lifecycleState }}'
CreationTypes:
- AutoCreated
- Attached
Outputs:
instanceIds:
Type: List
ValueSelector: 'ScalingInstances.ScalingInstance | map({"InstanceId": (.InstanceId), "LifecycleState": (.LifecycleState)})[]'
- Name: whetherTheScalingGroupInstanceIsEmpty
Action: 'ACS::Choice'
Description:
en: Checks if the scaling group has any instances that match the specified state.
zh-cn: 检查伸缩组内服务中的实例是否为空
Properties:
DefaultTask: whetherTosuspendProcess
Choices:
- When:
'Fn::Equals':
- [ ]
- '{{ getInstance.instanceIds }}'
NextTask: 'ACS::END'
- Name: whetherTosuspendProcess
Action: 'ACS::Choice'
Description:
en: Determines whether to suspend scaling processes based on the enterProcess parameter.
zh-cn: 根据流程值判断是否暂停流程
Properties:
DefaultTask: suspendProcess
Choices:
- When:
'Fn::Equals':
- []
- '{{ enterProcess }}'
NextTask: invokeByRunCommand
- Name: suspendProcess
Action: 'ACS::ExecuteAPI'
Description:
en: Suspends the specified scaling group processes.
zh-cn: 暂停伸缩组流程
Properties:
Service: ESS
API: SuspendProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ enterProcess }}'
- Name: invokeByRunCommand
Action: 'ACS::ESS::RunCommand'
Description:
en: Runs the specified command on the target instances by using Cloud Assistant.
zh-cn: 执行云助手命令
Properties:
commandContent: '{{ invokeScript }}'
instanceId:
Fn::Select:
- 'InstanceId'
- '{{ ACS::TaskLoopItem }}'
lifecycleState:
Fn::Select:
- 'LifecycleState'
- '{{ ACS::TaskLoopItem }}'
commandType: '{{ commandType }}'
scalingGroupId: '{{ scalingGroupId }}'
Loop:
Items: '{{ getInstance.instanceIds }}'
BatchPauseOption: '{{ batchPauseOption }}'
Concurrency:
'Fn::CalculateBatch':
- '{{ batchNumber }}'
- '{{ getInstance.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
- Name: tagInstance
Action: ACS::ExecuteApi
Description:
en: Applies a tag to the updated ECS instances for tracking.
zh-cn: 创建并挂载标签到ECS实例
Properties:
Service: ECS
API: TagResources
Parameters:
ResourceIds:
- Fn::Select:
- 'InstanceId'
- '{{ ACS::TaskLoopItem }}'
ResourceType: Instance
Tags:
- Key: 'ess:rollingupdate'
Value: 'oos:{{ ACS::ExecutionId }}'
Loop:
Items: '{{ getInstance.instanceIds }}'
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
- Name: whetherToResumeProcesses
Action: 'ACS::Choice'
Description:
en: Determines whether to resume scaling processes based on the exitProcess parameter.
zh-cn: 根据流程值判断是否恢复流程
Properties:
DefaultTask: resumeProcesses
Choices:
- When:
'Fn::Equals':
- []
- '{{ exitProcess }}'
NextTask: 'ACS::END'
- Name: resumeProcesses
Action: 'ACS::ExecuteAPI'
OnSuccess: 'ACS::END'
Description:
en: Resumes the specified scaling group processes.
zh-cn: 恢复伸缩组流程
Properties:
Service: ESS
API: ResumeProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ exitProcess }}'
- Name: getExecutionInstanceIds
Action: 'ACS::ExecuteAPI'
Description:
en: Retrieves the instance IDs from a previous execution for a rollback.
zh-cn: 获取已经执行过执行脚本的实例
Properties:
Service: OOS
API: ListExecutions
Parameters:
ParentExecutionId: '{{ sourceExecutionId }}'
Outputs:
instanceIds:
Type: List
ValueSelector: 'Executions[].Parameters.instanceId'
lifecycleStates:
Type: List
ValueSelector: '.Executions | map({"InstanceId": (.Parameters.instanceId), "LifecycleState": (.Parameters.lifecycleState)})[]'
- Name: getExistInstanceIds
Description:
en: Filters the list of instances to include only those that still exist.
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: Retrieves the process parameters from the original execution.
zh-cn: 获取源执行的参数
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: Suspends the scaling group processes for a rollback.
zh-cn: 暂停伸缩组流程
Properties:
Service: ESS
API: SuspendProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ getRollbackProcess.enterProcess }}'
- Name: rollbackByRunCommand
Action: 'ACS::ESS::RunCommand'
Description:
en: Runs the rollback command by using Cloud Assistant.
zh-cn: 执行云助手命令
Properties:
commandContent: '{{ rollbackScript }}'
instanceId: '{{ ACS::TaskLoopItem }}'
lifecycleState:
Fn::Jq:
- First
- '.[] | select(.InstanceId == "{{ ACS::TaskLoopItem }}") | .LifecycleState'
- '{{ getExecutionInstanceIds.lifecycleStates }}'
commandType: RunShellScript
scalingGroupId: '{{ scalingGroupId }}'
rollBack: 'true'
Loop:
Items: '{{ getExistInstanceIds.instanceIds }}'
BatchPauseOption: '{{ batchPauseOption }}'
Concurrency:
'Fn::CalculateBatch':
- '{{ batchNumber }}'
- '{{ getExistInstanceIds.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
- Name: whetherToResumeProcessesWithRollback
Action: 'ACS::Choice'
Description:
en: Determines whether to resume scaling processes after a rollback.
zh-cn: 根据流程值判断是否恢复流程
Properties:
DefaultTask: resumeProcessesWithRollback
Choices:
- When:
'Fn::Equals':
- []
- '{{ getRollbackProcess.exitProcess }}'
NextTask: 'ACS::END'
- Name: resumeProcessesWithRollback
Action: 'ACS::ExecuteAPI'
Description:
en: Resumes the scaling group processes after a rollback.
zh-cn: 恢复伸缩组流程
Properties:
Service: ESS
API: ResumeProcesses
Parameters:
ScalingGroupId: '{{ scalingGroupId }}'
Process: '{{ getRollbackProcess.exitProcess }}'
Outputs:
commandOutputs:
Type: List
Value:
'Fn::If':
- 'Fn::Equals':
- invoke
- '{{ invokeType }}'
- '{{ invokeByRunCommand.commandOutputs }}'
- '{{ rollbackByRunCommand.commandOutputs }}'