テンプレート名
コマンドを実行して、スケーリンググループ内の ECS インスタンスのローリングアップデートを行います。
テンプレートの説明
コマンドを実行して、スケーリンググループ内の ECS インスタンスのローリングアップデートを行います。
テンプレートのタイプ
自動化
所有者
Alibaba Cloud
入力パラメーター
|
パラメーター |
説明 |
タイプ |
必須 |
デフォルト |
制約 |
|
invokeType |
操作のタイプです。 |
String |
はい |
||
|
scalingGroupId |
ターゲットの ECS インスタンスを含むスケーリンググループの ID です。 |
String |
はい |
||
|
enterProcess |
更新が開始される前に一時停止するスケーリンググループのプロセスです。これらのプロセスを一時停止することで、Auto Scaling が更新に干渉するのを防ぎます。 |
List |
いいえ |
|
|
|
exitProcess |
更新完了後に再開するスケーリンググループのプロセスです。通常は |
List |
いいえ |
|
|
|
lifecycleState |
ターゲットインスタンスのライフサイクル状態です。アクティブなインスタンスには |
List |
いいえ |
InService |
|
|
commandType |
実行するスクリプトのタイプです。有効な値: |
String |
いいえ |
RunShellScript |
|
|
invokeScript |
各インスタンスで実行する更新スクリプトです。たとえば、最新のアプリケーションコードをプルしてサービスを再起動するシェルスクリプトなどです。 |
String |
いいえ |
"" |
|
|
rollbackScript |
各インスタンスで実行するロールバックスクリプトです。このスクリプトは、 |
String |
いいえ |
"" |
|
|
sourceExecutionId |
ロールバックする元の OOS 実行の ID です。 |
String |
いいえ |
"" |
|
|
batchPauseOption |
バッチ間の一次停止ポリシーです。 |
String |
いいえ |
Automatic |
|
|
batchNumber |
インスタンスを分割するバッチ数です。たとえば、10 個のインスタンスがあり、これを |
Number |
いいえ |
5 |
|
|
OOSAssumeRole |
OOS が更新を実行する際に引き受ける RAM ロールです。指定しない場合、OOS は現在のユーザーの権限を使用します。 |
String |
いいえ |
"" |
出力パラメーター
|
パラメーター |
説明 |
タイプ |
|
commandOutputs |
各インスタンスからのコマンド出力です。 |
List |
必要な権限ポリシー
{
"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"
}
]
}
詳細
ACS-ESS-RollingUpdateByRunCommandInScalingGroup の詳細
テンプレートの内容
FormatVersion: OOS-2019-06-01
Description:
en: Performs a rolling update on ECS instances in a scaling group by executing a command.
ja: コマンドを実行して、スケーリンググループ内の ECS インスタンスのローリングアップデートを行います。
zh-cn: 通过执行命令的方式滚动更新伸缩组内的ECS实例
name-en: Perform Rolling Update in Scaling Group by Running Command
name-ja: コマンド実行によるスケーリンググループのローリングアップデート
name-zh-cn: 通过执行命令的方式滚动更新伸缩组内的ECS实例
categories:
- elastic_manage
Parameters:
invokeType:
Label:
en: InvokeType
ja: 操作タイプ
zh-cn: 操作类型
Type: String
AllowedValues:
- invoke
- rollback
scalingGroupId:
Label:
en: ScalingGroupId
ja: スケーリンググループ ID
zh-cn: 伸缩组ID
Type: String
enterProcess:
Label:
en: EnterProcess
ja: 実行開始時に一時停止するスケーリンググループのプロセス
zh-cn: 执行开始要暂停的伸缩组流程
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
exitProcess:
Label:
en: ExitProcess
ja: 実行終了時に再開するスケーリンググループのプロセス
zh-cn: 执行结束要恢复的伸缩组流程
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
lifecycleState:
Label:
en: LifecycleState
ja: ライフサイクル状態
zh-cn: 生命周期状态
Description:
en: The lifecycle state of the target ECS instance.
ja: ターゲット ECS インスタンスのライフサイクル状態。
zh-cn: 要升级的ECS实例所处的生命周期状态
Type: List
AllowedValues:
- InService
- Protected
Default: InService
commandType:
Label:
en: CommandType
ja: コマンドタイプ
zh-cn: 命令类型
Type: String
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
invokeScript:
Label:
en: InvokeScript
ja: 実行用スクリプト
zh-cn: 用于执行的脚本
Type: String
Default: ''
rollbackScript:
Label:
en: RollbackScript
ja: ロールバック用スクリプト
zh-cn: 用于回滚的脚本
Type: String
Default: ''
sourceExecutionId:
Label:
en: SourceExecutionId
ja: ロールバック用の OOS 実行 ID
zh-cn: 用于回滚的OOS执行ID
Type: String
Default: ''
batchPauseOption:
Label:
en: BatchPauseOption
ja: バッチ一時停止オプション
zh-cn: 分批模式
Type: String
AllowedValues:
- Automatic
- FirstBatchPause
- EveryBatchPause
Default: Automatic
batchNumber:
Label:
en: BatchNumber
ja: バッチ数
zh-cn: 分批执行的批次
Type: Number
MinValue: 1
MaxValue: 100
Default: 5
OOSAssumeRole:
Label:
en: OOSAssumeRole
ja: OOS が引き受ける RAM ロール
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.
ja: 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.
ja: スケーリンググループ内の ECS インスタンスを取得します。
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.
ja: 指定された状態に一致するインスタンスがスケーリンググループに存在するかどうかを確認します。
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.
ja: enterProcess パラメーターに基づいてスケーリンググループのプロセスを一時停止するかどうかを決定します。
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.
ja: 指定されたスケーリンググループのプロセスを一時停止します。
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.
ja: 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.
ja: 追跡のために、更新された ECS インスタンスにタグを適用します。
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.
ja: exitProcess パラメーターに基づいてスケーリンググループのプロセスを再開するかどうかを決定します。
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.
ja: 指定されたスケーリンググループのプロセスを再開します。
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.
ja: ロールバックのために、以前の実行からインスタンス ID を取得します。
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.
ja: インスタンスのリストをフィルタリングして、まだ存在するインスタンスのみを含めます。
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.
ja: 元の実行からプロセスパラメーターを取得します。
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.
ja: ロールバックのためにスケーリンググループのプロセスを一時停止します。
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.
ja: 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.
ja: ロールバック後にスケーリンググループのプロセスを再開するかどうかを決定します。
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.
ja: ロールバック後にスケーリンググループのプロセスを再開します。
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 }}'