Nome do modelo
ACS-ECS-CreateAndCopyImage
Descrição do modelo
Este modelo cria uma imagem do Elastic Compute Service (ECS) e a clona para outras regiões, ideal para cenários como atualizações de sistema e backups. Os parâmetros obrigatórios são: regionId (região da instância ECS de origem), instanceId (instância ECS) e targetImageName (nome da nova imagem). Opcionalmente, especifique commandContent para executar scripts na instância antes da criação da imagem. A imagem é então clonada para as regiões de destino (targetRegionIds) e pode ser compartilhada com outras contas Alibaba Cloud (accountIds). O modelo retorna os IDs das imagens criadas e clonadas.
Tipo de modelo
Automatizado
Proprietário
Alibaba Cloud
Parâmetros de entrada
|
Parâmetro |
Descrição |
Tipo |
Obrigatório |
Valor padrão |
Limite |
|
instanceId |
ID da instância ECS. |
String |
Sim |
||
|
regionId |
Região da instância ECS para a qual criar a imagem. |
String |
Não |
{{ ACS::RegionId }} |
|
|
targetImageName |
Nome da nova imagem ECS. |
String |
Não |
CreateImage_from_{{ACS::ExecutionId}} |
|
|
commandType |
Tipo de comando do Cloud Assistant. |
String |
Não |
RunShellScript |
|
|
commandContent |
Comando do Cloud Assistant. |
String |
Não |
"" |
|
|
targetRegionIds |
Regiões de destino para clonagem da imagem ECS. |
List |
Não |
[] |
|
|
accountIds |
Contas Alibaba Cloud para compartilhamento da imagem personalizada. |
List |
Não |
[] |
|
|
scalingConfigurationIds |
Configurações de dimensionamento a modificar. |
List |
Não |
[] |
|
|
launchTemplateNames |
Nomes dos modelos de inicialização a atualizar. |
List |
Não |
[] |
|
|
tags |
Tags da imagem ECS. |
Json |
Não |
[] |
|
|
rateControl |
Configurações de controle de taxa. |
Json |
Não |
{'Mode': 'Concurrency', 'MaxErrors': '0', 'Concurrency': 5} |
|
|
OOSAssumeRole |
Função RAM assumida pelo CloudOps Orchestration Service (OOS). |
String |
Não |
"" |
Parâmetros de saída
|
Parâmetro |
Descrição |
Tipo |
|
imageIds |
List |
|
|
imageIdAndRegion |
List |
Política de permissões necessária para executar o modelo
{
"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"
}
]
}
Referências
Para obter mais informações, consulte ACS-ECS-CreateAndCopyImage.yml no GitHub.
Conteúdo do modelo
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