模板名稱
ACS-ECS-CreateAndCopyImage 建立ECS鏡像並同步到其它地區
模板描述
建立一個新ECS鏡像並且複製新鏡像到其他地區,適用於需要建立和同步ECS鏡像到不同地區的情境,例如系統更新和備份。在配置過程中,使用者需要提供以下必填參數資訊:地區ID(regionId):用於指定需要建立鏡像的ECS執行個體所在的地區,ECS執行個體ID(instanceId):用於指定要建立鏡像的執行個體,目標鏡像名稱(targetImageName):用於為新的ECS鏡像命名。此外,使用者可以選擇性地通過雲助手命令(commandContent)在執行個體上運行指令碼任務。建立後的鏡像將被同步到指定的目標地區(targetRegionIds),使用者也可以選擇共用鏡像到其他阿里雲賬戶(accountIds)。模板在執行後會返回建立和複製的鏡像ID列表,方便使用者驗證操作結果。
模板類型
自動化
所有者
Alibaba Cloud
輸入參數
參數名稱 | 描述 | 類型 | 是否必填 | 預設值 | 約束 |
instanceId | ECS執行個體ID | String | 是 | ||
regionId | 地區ID | String | 否 | {{ ACS::RegionId }} | |
targetImageName | 新鏡像的名稱 | String | 否 | CreateImage_from_{{ACS::ExecutionId}} | |
commandType | 雲助手命令類型 | String | 否 | RunShellScript | |
commandContent | 雲助手命令 | String | 否 | “” | |
targetRegionIds | 目標地區ID | List | 否 | [] | |
accountIds | 授權共用鏡像的阿里雲帳號ID | List | 否 | [] | |
scalingConfigurationIds | 待修改的伸縮配置ID | List | 否 | [] | |
launchTemplateNames | 待更新的執行個體啟動模板名稱列表 | List | 否 | [] | |
tags | 鏡像標籤 | Json | 否 | [] | |
rateControl | 任務執行的並發比率 | Json | 否 | {‘Mode’: ‘Concurrency’, ‘MaxErrors’: 0, ‘Concurrency’: 5} | |
OOSAssumeRole | OOS扮演的RAM角色 | String | 否 | “” |
輸出參數
參數名稱 | 描述 | 類型 |
imageIds | List | |
imageIdAndRegion | List |
執行此模板需要的權限原則
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:CopyImage",
"ecs:CreateImage",
"ecs:CreateLaunchTemplateVersion",
"ecs:DeleteLaunchTemplateVersion",
"ecs:DescribeImages",
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:DescribeLaunchTemplateVersions",
"ecs:DescribeLaunchTemplates",
"ecs:DescribeRegions",
"ecs:ModifyImageSharePermission",
"ecs:ModifyLaunchTemplateDefaultVersion",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ess:ModifyScalingConfiguration"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳情
模板內容
FormatVersion: OOS-2019-06-01
Description:
name-en: ACS-ECS-CreateAndCopyImage
name-zh-cn: 建立ECS鏡像並同步到其它地區
en: 'Creates an ECS image and copies the new image to other regions, applicable to scenarios requiring creation and synchronization of ECS images across different regions, such as system updates and backups. During configuration, users need to provide the following required parameter information: Region ID (regionId), which specifies the region of the ECS instance for which the image will be created, ECS Instance ID (instanceId), which identifies the instance to create the image from, and Target Image Name (targetImageName), which names the new ECS image. Optionally, users may execute tasks on the instance via cloud assistant commands (commandContent). The created image will be synchronized to specified target regions (targetRegionIds), and users can also opt to share the image with other Alibaba Cloud accounts (accountIds). Upon execution, the template will return a list of the created and cloned image IDs, facilitating verification of the operations.'
zh-cn: 建立一個新ECS鏡像並且複製新鏡像到其他地區,適用於需要建立和同步ECS鏡像到不同地區的情境,例如系統更新和備份。在配置過程中,使用者需要提供以下必填參數資訊:地區ID(regionId):用於指定需要建立鏡像的ECS執行個體所在的地區,ECS執行個體ID(instanceId):用於指定要建立鏡像的執行個體,目標鏡像名稱(targetImageName):用於為新的ECS鏡像命名。此外,使用者可以選擇性地通過雲助手命令(commandContent)在執行個體上運行指令碼任務。建立後的鏡像將被同步到指定的目標地區(targetRegionIds),使用者也可以選擇共用鏡像到其他阿里雲賬戶(accountIds)。模板在執行後會返回建立和複製的鏡像ID列表,方便使用者驗證操作結果。
categories:
- image_manage
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: 地區ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
instanceId:
Label:
en: InstanceId
zh-cn: ECS執行個體ID
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
RegionId: regionId
targetImageName:
Label:
en: TargetImageName
zh-cn: 新鏡像的名稱
Type: String
Description:
en: <p class="p">Note:</p> <ul class="ul"> <li class="li">Length is 2~128 English or Chinese characters</li> <li class="li"><font color='red'>must start with big or small letters or Chinese, not http:// and https://. </font></li> <li class="li">Can contain numbers, colons (:), underscores (_), or dashes (-). </li> </ul>
zh-cn: <p class="p">注意:</p> <ul class="ul"> <li class="li">長度為2~128個英文或中文字元</li> <li class="li"><font color='red'>必須以大小字母或中文開頭,不能以http://和https://開頭。</font></li> <li class="li">可以包含數字、半形冒號(:)、底線(_)或者短劃線(-)。</li> </ul>
Default: CreateImage_from_{{ACS::ExecutionId}}
commandType:
Label:
en: CommandType
zh-cn: 雲助手命令類型
Type: String
AllowedValues:
- RunShellScript
- RunBatScript
- RunPowerShellScript
Default: RunShellScript
commandContent:
Description:
en: <font color='red'><b>Command is not executed when value is empty</b></font>
zh-cn: <font color='red'><b>命令為空白時不會執行命令</b></font>
Label:
en: CommandContent
zh-cn: 雲助手命令
Type: String
AssociationProperty: Code
Default: ''
targetRegionIds:
Label:
en: TargetRegionIds
zh-cn: 目標地區ID
Type: List
AllowedValues:
- all-regions
- cn-beijing
- cn-qingdao
- cn-zhangjiakou
- cn-huhehaote
- cn-hangzhou
- cn-shanghai
- cn-shenzhen
- cn-chengdu
- cn-hongkong
- cn-heyuan
- cn-wulanchabu
- ap-northeast-1
- ap-southeast-1
- ap-southeast-2
- ap-southeast-3
- ap-southeast-5
- ap-south-1
- us-east-1
- us-west-1
- eu-west-1
- me-east-1
- eu-central-1
Default: []
accountIds:
Label:
en: AccountIds
zh-cn: 授權共用鏡像的阿里雲帳號ID
Type: List
Default: []
scalingConfigurationIds:
Description:
en: <font color='red'><b>Must correspond to the selected region</b></font>
zh-cn: <font color='red'><b>必須要在所選的地區</b></font>
Label:
en: ScalingConfigurationIds
zh-cn: 待修改的伸縮配置ID
Type: List
Default: []
launchTemplateNames:
Description:
en: <font color='red'><b>Must correspond to the selected region</b></font>
zh-cn: <font color='red'><b>必須要在所選的地區</b></font>
Label:
en: LaunchTemplateNames
zh-cn: 待更新的執行個體啟動模板名稱列表
Type: List
Default: []
tags:
Label:
en: Tags
zh-cn: 鏡像標籤
Type: Json
AssociationProperty: Tags
AssociationPropertyMetadata:
ShowSystem: false
Default: []
rateControl:
Label:
en: RateControl
zh-cn: 任務執行的並發比率
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 5
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: whetherToRunCommand
Action: 'ACS::Choice'
Description:
en: Choose next task
zh-cn: 選擇下一個任務
Properties:
DefaultTask: runCommand
Choices:
- When:
'Fn::Equals':
- ''
- '{{ commandContent }}'
NextTask: createImage
- Name: runCommand
Action: 'ACS::ECS::RunCommand'
Description:
en: Run cloud assistant command on ECS instance
zh-cn: 在執行個體中運行雲助手命令
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ instanceId }}'
commandContent: '{{ commandContent }}'
commandType: '{{ commandType }}'
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
- Name: createImage
Action: 'ACS::ECS::CreateImage'
Description:
en: Create new image with the specified image name and instance ID
zh-cn: 通過指定執行個體ID和鏡像名稱建立新的鏡像
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ instanceId }}'
imageName: '{{ targetImageName }}-{{ ACS::CurrentUTCTime }}'
tags: '{{tags}}'
Outputs:
imageId:
ValueSelector: imageId
Type: String
- Name: queryAllAvailableRegions
Action: 'ACS::ExecuteAPI'
Description:
en: View all available regions
zh-cn: 查詢當前所有可用地區
Properties:
Service: ECS
API: DescribeRegions
Parameters:
RegionId: '{{ regionId }}'
Outputs:
regionIds:
Type: List
ValueSelector: 'Regions.Region[]|.RegionId|select([scan("{{ACS::RegionId}}|test")]|length<1)'
allRegionsChosen:
Type: String
ValueSelector: '.|{{targetRegionIds}}|sort|.[0]'
- Name: whetherCloneToAllRegions
Action: 'ACS::Choice'
Description:
en: Choose next task by targetRegionIds Chosen
zh-cn: 根據所選目的地區判斷下一步執行
Properties:
DefaultTask: copyImage
Choices:
- When:
'Fn::Equals':
- all-regions
- '{{ queryAllAvailableRegions.allRegionsChosen }}'
NextTask: copyImageToAllRegions
- Name: copyImage
Action: 'ACS::ECS::CopyImage'
OnSuccess: whetherToShareImage
Description:
en: Copy image to regions chosen
zh-cn: 複製鏡像到被指定的地區
Properties:
regionId: '{{ regionId }}'
imageId: '{{ createImage.imageId }}'
targetImageName: '{{ targetImageName }}-{{ ACS::CurrentUTCTime }}'
targetRegionId: '{{ ACS::TaskLoopItem }}'
Loop:
Items: '{{ targetRegionIds }}'
RateControl: '{{ rateControl }}'
Outputs:
imageIdsWithRegion:
AggregateType: 'Fn::ListJoin'
AggregateField: imageIdWithRegion
Outputs:
imageIdWithRegion:
ValueSelector: '.|(.imageId),"{{ ACS::TaskLoopItem }}"'
Type: List
- Name: copyImageToAllRegions
Action: 'ACS::ECS::CopyImage'
Description:
en: Copy image to all available regions
zh-cn: 複製鏡像到所有可用地區
Properties:
regionId: '{{ regionId }}'
imageId: '{{ createImage.imageId }}'
targetImageName: '{{ targetImageName }}-{{ ACS::CurrentUTCTime }}'
targetRegionId: '{{ ACS::TaskLoopItem }}'
Loop:
Items: '{{ queryAllAvailableRegions.regionIds }}'
RateControl: '{{ rateControl }}'
Outputs:
imageIdsWithRegion:
AggregateType: 'Fn::ListJoin'
AggregateField: imageIdWithRegion
Outputs:
imageIdWithRegion:
ValueSelector: '.|(.imageId),"{{ ACS::TaskLoopItem }}"'
Type: List
- Name: whetherToShareImage
Action: 'ACS::Choice'
Description:
en: Choose next task by accountIds
zh-cn: 根據輸入賬戶值判斷下一步執行
Properties:
DefaultTask: shareImage
Choices:
- When:
'Fn::Equals':
- []
- '{{ accountIds }}'
NextTask: modifyScalingConfiguration
- Name: shareImage
Action: 'ACS::ExecuteAPI'
Description:
en: Shares a custom image to other Alibaba Cloud accounts
zh-cn: 共用自訂鏡像到其他阿里雲帳號
Properties:
Service: ECS
API: ModifyImageSharePermission
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ createImage.imageId }}'
AddAccount: '{{ accountIds }}'
- Name: modifyScalingConfiguration
Action: 'ACS::ExecuteAPI'
OnError: ACS::NEXT
Description:
en: Modify scaling configuration
zh-cn: 修改伸縮配置
Properties:
Service: ESS
API: ModifyScalingConfiguration
Parameters:
RegionId: '{{ regionId }}'
ScalingConfigurationId: '{{ ACS::TaskLoopItem }}'
ImageId: '{{ createImage.imageId }}'
Loop:
Items: '{{ scalingConfigurationIds }}'
- Name: updateLaunchTemplate
Action: 'ACS::ECS::UpdateLaunchTemplate'
Description:
en: Update instance launch template
zh-cn: 更新執行個體啟動模板
Properties:
regionId: '{{ regionId }}'
imageId: '{{ createImage.imageId }}'
launchTemplateName: '{{ ACS::TaskLoopItem }}'
Loop:
Items: '{{ launchTemplateNames }}'
Outputs:
imageIds:
Type: List
Value: '{{ createImage.imageId }}'
imageIdAndRegion:
Type: List
Value:
'Fn::If':
- 'Fn::Equals':
- all-regions
- '{{ queryAllAvailableRegions.allRegionsChosen }}'
- '{{ copyImageToAllRegions.imageIdsWithRegion }}'
- '{{ copyImage.imageIdsWithRegion }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- regionId
- instanceId
Label:
default:
zh-cn: 選擇執行個體
en: Select Ecs Instances
- Parameters:
- targetImageName
- tags
Label:
default:
zh-cn: 鏡像設定
en: Image Configure
- Parameters:
- commandType
- commandContent
Label:
default:
zh-cn: 發送遠程命令
en: Run Command
- Parameters:
- targetRegionIds
- accountIds
Label:
default:
zh-cn: 鏡像分發
en: Copy Image
- Parameters:
- scalingConfigurationIds
- launchTemplateNames
- rateControl
- OOSAssumeRole
Label:
default:
zh-cn: 進階選項
en: Control Options