テンプレート名
ACS-ECS-CreateAndCopyImage
テンプレートの説明
Elastic Compute Service (ECS) イメージを作成し、そのイメージを他のリージョンにクローン作成します。これは、システムの更新やバックアップなど、ECS イメージを作成して他のリージョンにクローン作成する必要があるシナリオに適用されます。このテンプレートを構成する場合は、次のパラメーターを指定する必要があります。regionId: イメージを作成する ECS インスタンスのリージョン、instanceId: ECS インスタンス、targetImageName: 作成するイメージの名前。また、commandContent を指定してインスタンス上でスクリプトを実行することもできます。イメージが作成されると、ターゲットリージョン (targetRegionIds) にクローン作成されます。また、accountIds を指定して、他の Alibaba Cloud アカウントにイメージをクローン作成することもできます。テンプレートが実行されると、作成およびクローン作成されたイメージの ID が返されます。
テンプレートタイプ
自動化
所有者
Alibaba Cloud
入力パラメーター
パラメーター | 説明 | タイプ | 必須 | デフォルト値 | 制限 |
instanceId | ECS インスタンスの ID。 | String | はい | ||
regionId | ECS イメージを作成するリージョンの ID。 | String | いいえ | {{ ACS::RegionId }} | |
targetImageName | 作成する ECS イメージの名前。 | String | いいえ | CreateImage_from_{{ACS::ExecutionId}} | |
commandType | クラウドアシスタントコマンドのタイプ。 | String | いいえ | RunShellScript | |
commandContent | クラウドアシスタントコマンド。 | String | いいえ | "" | |
targetRegionIds | ECS イメージのクローン作成先のリージョンの ID。 | List | いいえ | [] | |
accountIds | カスタムイメージを共有する Alibaba Cloud アカウントの ID。 | List | いいえ | [] | |
scalingConfigurationIds | 変更するスケーリング設定の ID。 | List | いいえ | [] | |
launchTemplateNames | 更新する起動テンプレート名のリスト。 | List | いいえ | [] | |
tags | ECS イメージのタグ。 | Json | いいえ | [] | |
rateControl | レート制御設定。 | Json | いいえ | {'Mode': 'Concurrency', 'MaxErrors': '0', 'Concurrency': 5} | |
OOSAssumeRole | CloudOps Orchestration Service (OOS) がアシュームする Resource Access Management (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"
}
]
}
参照
詳細については、GitHub の ACS-ECS-CreateAndCopyImage.yml をご参照ください。
テンプレートコンテンツ
FormatVersion: OOS-2019-06-01
Description:
name-en: ACS-ECS-CreateAndCopyImage
name-zh-cn: the description in Chinese
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: the description in Chinese
categories:
- image_manage
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: the description in Chinese
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
instanceId:
Label:
en: InstanceId
zh-cn: the description in Chinese
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
RegionId: regionId
targetImageName:
Label:
en: TargetImageName
zh-cn: the description in Chinese
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: the description in Chinese </li> </ul>
Default: CreateImage_from_{{ACS::ExecutionId}}
commandType:
Label:
en: CommandType
zh-cn: the description in Chinese
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: the description in Chinese
Label:
en: CommandContent
zh-cn: the description in Chinese
Type: String
AssociationProperty: Code
Default: ''
targetRegionIds:
Label:
en: TargetRegionIds
zh-cn: the description in Chinese
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: the description in Chinese
Type: List
Default: []
scalingConfigurationIds:
Description:
en: <font color='red'><b>Must correspond to the selected region</b></font>
zh-cn: the description in Chinese
Label:
en: ScalingConfigurationIds
zh-cn: the description in Chinese
Type: List
Default: []
launchTemplateNames:
Description:
en: <font color='red'><b>Must correspond to the selected region</b></font>
zh-cn: the description in Chinese
Label:
en: LaunchTemplateNames
zh-cn: the description in Chinese
Type: List
Default: []
tags:
Label:
en: Tags
zh-cn: the description in Chinese
Type: Json
AssociationProperty: Tags
AssociationPropertyMetadata:
ShowSystem: false
Default: []
rateControl:
Label:
en: RateControl
zh-cn: the description in Chinese
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 5
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: the description in Chinese
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: whetherToRunCommand
Action: 'ACS::Choice'
Description:
en: Choose next task
zh-cn: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
en: Select Ecs Instances
- Parameters:
- targetImageName
- tags
Label:
default:
zh-cn: the description in Chinese
en: Image Configure
- Parameters:
- commandType
- commandContent
Label:
default:
zh-cn: the description in Chinese
en: Run Command
- Parameters:
- targetRegionIds
- accountIds
Label:
default:
zh-cn: the description in Chinese
en: Copy Image
- Parameters:
- scalingConfigurationIds
- launchTemplateNames
- rateControl
- OOSAssumeRole
Label:
default:
zh-cn: the description in Chinese
en: Control Options