全部產品
Search
文件中心

CloudOps Orchestration Service:ACS-ECS-CreateAndCopyImage

更新時間:Sep 06, 2024

模板名稱

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