文档

ACS-ECS-CreateAndCopyImage

更新时间:

模板名称

ACS-ECS-CreateAndCopyImage 创建ECS镜像并同步到其它地域

立即执行

模板描述

创建一个新ECS镜像并且克隆新镜像到其他地域

模板类型

自动化

所有者

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"
        }
    ]
}

详情

ACS-ECS-CreateAndCopyImage详情

模板内容

FormatVersion: OOS-2019-06-01
Description:
  name-en: ACS-ECS-CreateAndCopyImage
  name-zh-cn: 创建ECS镜像并同步到其它地域
  en: Creates an ECS image and copy new image
  zh-cn: 创建一个新ECS镜像并且克隆新镜像到其他地域
  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