テンプレート名
ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand
テンプレートの説明
Object Storage Service (OSS) オブジェクトをダウンロードし、コマンドを実行して、スケーリンググループ内の Elastic Compute Service (ECS) インスタンスにローリングアップデートを実行します。
テンプレートタイプ
自動
所有者
Alibaba Cloud
入力パラメーター
|
パラメーター |
説明 |
タイプ |
必須 |
デフォルト値 |
制限 |
|
invokeType |
操作タイプ |
文字列 |
はい |
||
|
scalingGroupId |
スケーリンググループの ID |
文字列 |
はい |
||
|
invokeBucketName |
ローリングアップデート用のオブジェクトを格納するバケット |
文字列 |
はい |
||
|
invokeObjectName |
ローリングアップデート用のオブジェクト |
文字列 |
はい |
||
|
invokeDestinationDir |
ローリングアップデート用のファイル保存ディレクトリ |
文字列 |
はい |
||
|
rollbackBucketName |
ロールバック用のオブジェクトを格納するバケット |
文字列 |
はい |
||
|
rollbackObjectName |
ロールバック用のオブジェクト |
文字列 |
はい |
||
|
rollbackDestinationDir |
ロールバック用のファイル保存ディレクトリ |
文字列 |
はい |
||
|
enterProcess |
実行前に一時停止するスケーリングプロセス |
リスト |
いいえ |
['ScaleIn', 'ScaleOut', 'HealthCheck', 'AlarmNotification', 'ScheduledAction'] |
|
|
exitProcess |
実行後に再開するスケーリングプロセス |
リスト |
いいえ |
['ScaleIn', 'ScaleOut', 'HealthCheck', 'AlarmNotification', 'ScheduledAction'] |
|
|
invokeScript |
ローリングアップデートの実行に使用されるスクリプト |
文字列 |
いいえ |
"" |
|
|
rollbackScript |
ロールバックの実行に使用されるスクリプト |
文字列 |
いいえ |
"" |
|
|
sourceExecutionId |
ロールバック元の OOS 実行 ID |
文字列 |
いいえ |
"" |
|
|
whetherSaveToFile |
オブジェクトの内容を特定のファイルに保存するかどうかを指定します。 |
ブール値 |
いいえ |
True |
|
|
URLExpirationTime |
OSS ファイルダウンロード URL の有効期限 |
数値 |
いいえ |
6000 |
|
|
OSSRegion |
OSS バケットが存在するリージョン |
文字列 |
いいえ |
{{ ACS::RegionId }} |
|
|
batchPauseOption |
バッチの一時停止ポリシー |
文字列 |
いいえ |
Automatic |
|
|
batchNumber |
バッチ数 |
数値 |
いいえ |
5 |
|
|
OOSAssumeRole |
OOS が引き受ける RAM ロール |
文字列 |
いいえ |
"" |
出力パラメーター
|
パラメーター |
説明 |
タイプ |
|
commandOutputs |
リスト |
テンプレートの実行に必要なポリシー
{
"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
テンプレートの内容
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文件并执行命令的方式滚动更新伸缩组内的ECS实例
ja: OSS ファイルをダウンロードしてコマンドを実行することにより、スケーリンググループ内の ECS インスタンスをローリングアップデートします
name-en: ACS-ESS-RollingUpdateByDownloadOSSFileAndRunCommand
name-zh-cn: 通过下载OSS文件并执行命令的方式滚动更新伸缩组内的ECS实例
name-ja: OSSファイルのダウンロードとコマンド実行によるスケーリンググループ内のECSインスタンスのローリングアップデート
categories:
- elastic_manage
Parameters:
invokeType:
Label:
en: InvokeType
zh-cn: 操作类型
ja: 操作タイプ
Type: String
AllowedValues:
- invoke
- rollback
scalingGroupId:
Label:
en: ScalingGroupId
zh-cn: 伸缩组ID
ja: スケーリンググループ ID
Type: String
enterProcess:
Label:
en: EnterProcess
zh-cn: 执行开始要暂停的伸缩组流程
ja: 実行前に一時停止するスケーリングプロセス
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
exitProcess:
Label:
en: ExitProcess
zh-cn: 执行结束要恢复的伸缩组流程
ja: 実行後に再開するスケーリングプロセス
Type: List
Default:
- ScaleIn
- ScaleOut
- HealthCheck
- AlarmNotification
- ScheduledAction
invokeBucketName:
Type: String
Label:
en: InvokeBucketName
zh-cn: 用于升级的Bucket名称
ja: ローリングアップデート用のバケット
invokeObjectName:
Label:
en: InvokeObjectName
zh-cn: 用于升级的Object名称
ja: ローリングアップデート用のオブジェクト
Type: String
invokeDestinationDir:
Label:
en: InvokeDestinationDir
zh-cn: 用于升级的文件存储目录
ja: ローリングアップデート用のファイル保存ディレクトリ
Type: String
invokeScript:
Label:
en: InvokeScript
zh-cn: 用于升级的脚本
ja: ローリングアップデート用のスクリプト
Type: String
AssociationProperty: Code
Default: ''
rollbackBucketName:
Type: String
Label:
en: RollbackBucketName
zh-cn: 用于回滚的Bucket名称
ja: ロールバック用のバケット
rollbackObjectName:
Label:
en: RollbackObjectName
zh-cn: 用于回滚的Object名称
ja: ロールバック用のオブジェクト
Type: String
rollbackDestinationDir:
Label:
en: InvokeDestinationDir
zh-cn: 用于回滚的文件存储目录
ja: ロールバック用のファイル保存ディレクトリ
Type: String
rollbackScript:
Label:
en: RollbackScript
zh-cn: 用于回滚的脚本
ja: ロールバック用のスクリプト
Type: String
AssociationProperty: Code
Default: ''
sourceExecutionId:
Label:
en: SourceExecutionId
zh-cn: 用于回滚的OOS执行ID
ja: ロールバック元の OOS 実行 ID
Type: String
Default: ''
whetherSaveToFile:
Label:
en: whetherSaveToFile
zh-cn: 是否将内容下载到特定文件
ja: 内容を特定のファイルにダウンロードするかどうか
Type: Boolean
Default: true
URLExpirationTime:
Label:
en: OOSFileDownloadURLExpirationTime
zh-cn: OSS文件下载链接的过期时间
ja: OSS ファイルダウンロード URL の有効期限
Type: Number
Default: 6000
OSSRegion:
Label:
en: OSSRegion
zh-cn: OSS所在地域
ja: 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所在地域和当前地域不同时会通过公网下载OSS文件,需要伸缩组内的ECS能访问公网。
ja: OSS があるリージョンが現在のリージョンと異なる場合、OSS ファイルはパブリックネットワーク経由でダウンロードされます。スケーリンググループ内の ECS インスタンスはパブリックネットワークにアクセスできる必要があります。
Type: String
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
batchPauseOption:
Label:
en: BatchPauseOption
zh-cn: 分批模式
ja: バッチ一時停止オプション
Type: String
AllowedValues:
- Automatic
- FirstBatchPause
- EveryBatchPause
Default: Automatic
batchNumber:
Label:
en: BatchNumber
zh-cn: 分批执行的批次
ja: バッチ数
Type: Number
MinValue: 1
MaxValue: 100
Default: 5
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
ja: OOS が引き受ける RAM ロール
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getLifecycleHook
Action: ACS::ExecuteAPI
Description:
en: Get lifecycle hook
zh-cn: 获取生命周期挂钩
ja: ライフサイクルフックの取得
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: 根据升级类型选择任务
ja: 操作タイプによる次のタスクの選択
Properties:
DefaultTask: getInstance
Choices:
- When:
'Fn::Equals':
- rollback
- '{{ invokeType }}'
NextTask: getExecutionInstanceIds
- Name: getInstance
Description:
en: Views the ECS instances
zh-cn: 获取ECS实例
ja: 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: 检查伸缩组内服务中的实例是否为空
ja: スケーリンググループ内のサービス中のインスタンスが空かどうかの確認
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: 根据流程值判断是否暂停流程
ja: プロセス値による次のタスクの選択
Properties:
DefaultTask: suspendProcess
Choices:
- When:
'Fn::Equals':
- []
- '{{ enterProcess }}'
NextTask: invokeByDownloadOSSFileAndRunCommand
- Name: suspendProcess
Action: 'ACS::ExecuteAPI'
Description:
en: Suspend process
zh-cn: 暂停伸缩组流程
ja: スケーリングプロセスの一時停止
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: 通过下载文件到实例并执行命令的方式进行升级
ja: インスタンスへのファイルのダウンロードとコマンドの実行によるローリングアップデート
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: 创建并挂载标签到ECS实例
ja: 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: 创建用于升级的生命周期挂钩
ja: ローリングアップデート用のライフサイクルフックの作成
Properties:
Service: ESS
API: CreateLifecycleHook
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
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: 修改用于升级的生命周期挂钩
ja: ローリングアップデート用のライフサイクルフックの変更
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: 根据流程值判断是否恢复流程
ja: プロセス値による次のタスクの選択
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: 恢复伸缩组流程
ja: スケーリングプロセスの再開
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: 获取已经执行过执行脚本的实例
ja: 実行済みのインスタンスの取得
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实例
ja: 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: 获取源执行的参数
ja: 元の実行のパラメーターを取得
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: 暂停伸缩组流程
ja: スケーリングプロセスの一時停止
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: 通过下载文件到实例并执行命令的方式进行回滚
ja: インスタンスへのファイルのダウンロードとコマンドの実行によるロールバック
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: 修改用于回滚的生命周期挂钩
ja: ロールバック用のライフサイクルフックの変更
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: 根据流程值判断是否恢复流程
ja: プロセス値による次のタスクの選択
Properties:
DefaultTask: resumeProcessesWithRollback
Choices:
- When:
'Fn::Equals':
- []
- '{{ getRollbackProcess.exitProcess }}'
NextTask: 'ACS::END'
- Name: resumeProcessesWithRollback
Action: 'ACS::ExecuteAPI'
Description:
en: Resume process
zh-cn: 恢复伸缩组流程
ja: スケーリングプロセスの再開
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 }}'