模板名稱
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