全部產品
Search
文件中心

CloudOps Orchestration Service:ACS-ESS-UpdateScalingConfigurationImage

更新時間:Sep 06, 2024

模板名稱

ACS-ESS-UpdateScalingConfigurationImage 更新Auto Scaling配置鏡像

立即執行

模板描述

通過運行命令更新一個已存在的ECS鏡像後建立一個新ECS鏡像並更新伸縮配置中的鏡像ID

模板類型

自動化

所有者

Alibaba Cloud

輸入參數

參數名稱

描述

類型

是否必填

預設值

約束

sourceImageId

源鏡像ID

String

securityGroupId

安全性群組ID

String

vSwitchId

交換器ID

String

commandContent

雲助手命令

String

scalingConfigurationIds

待修改的伸縮配置ID列表

List

regionId

地區ID

String

{{ ACS::RegionId }}

targetImageName

新鏡像的名稱

String

UpdateImage_from_{{ sourceImageId }}on{{ ACS::ExecutionId }}

instanceType

ECS執行個體類型

String

ecs.g5.large

字串校正Regex : ecs.[A-Za-z0-9.-]*

commandType

雲助手命令類型

String

RunShellScript

tags

鏡像標籤

Json

[]

OOSAssumeRole

OOS扮演的RAM角色

String

""

輸出參數

參數名稱

描述

類型

imageId

String

執行此模板需要的權限原則

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:CreateImage",
                "ecs:DeleteInstance",
                "ecs:DescribeCloudAssistantStatus",
                "ecs:DescribeImages",
                "ecs:DescribeInstances",
                "ecs:DescribeInvocationResults",
                "ecs:DescribeInvocations",
                "ecs:InstallCloudAssistant",
                "ecs:RebootInstance",
                "ecs:RunCommand",
                "ecs:RunInstances",
                "ecs:StopInstance"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "ess:ModifyScalingConfiguration"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

詳情

ACS-ESS-UpdateScalingConfigurationImage詳情

模板內容

FormatVersion: OOS-2019-06-01
Description:
  en: Updates an existing ECS image via ECS Cloud Assistant then creates an ECS image and updates scaling configuration image ID
  zh-cn: 通過運行命令更新一個已存在的ECS鏡像後建立一個新ECS鏡像並更新伸縮配置中的鏡像ID
  name-en: ACS-ESS-UpdateScalingConfigurationImage
  name-zh-cn: 更新Auto Scaling配置鏡像
  categories:
    - elastic_manage
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: 地區ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  targetImageName:
    Label:
      en: NewImageName
      zh-cn: 新鏡像的名稱
    Type: String
    Default: UpdateImage_from_{{ sourceImageId }}_on_{{ ACS::ExecutionId }}
  sourceImageId:
    Label:
      en: SourceImageId
      zh-cn: 源鏡像ID
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
    AssociationPropertyMetadata:
      RegionId: regionId
  instanceType:
    Label:
      en: InstanceType
      zh-cn: ECS執行個體類型
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AllowedPattern: ecs\.[A-Za-z0-9\.\-]*
    Default: 'ecs.g5.large'
  securityGroupId:
    Label:
      en: SecurityGroupId
      zh-cn: 安全性群組ID
    Type: String
    AssociationProperty: 'ALIYUN::ECS::SecurityGroup::SecurityGroupId'
    AssociationPropertyMetadata:
      RegionId: regionId
  vSwitchId:
    Label:
      en: VSwitchId
      zh-cn: 交換器ID
    Type: String
    AssociationProperty: 'ALIYUN::VPC::VSwitch::VSwitchId'
    AssociationPropertyMetadata:
      RegionId: regionId
      Filters:
        - SecurityGroupId: securityGroupId
  commandType:
    Label:
      en: CommandType
      zh-cn: 雲助手命令類型
    Type: String
    AllowedValues:
      - RunBatScript
      - RunPowerShellScript
      - RunShellScript
    Default: RunShellScript
  commandContent:
    Label:
      en: CommandContent
      zh-cn: 雲助手命令
    Type: String
    AssociationProperty: Code
  scalingConfigurationIds:
    Label:
      en: ScalingConfigurationIds
      zh-cn: 待修改的伸縮配置ID列表
    Type: List
  tags:
    Label:
      en: ImageTags
      zh-cn: 鏡像標籤
    Type: Json
    AssociationProperty: Tags
    AssociationPropertyMetadata:
      ShowSystem: false
    Default: []
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: checkNewImageName
  Action: ACS::CheckFor
  Description:
    en: Check image name is available
    zh-cn: 檢查鏡像名稱是可用的
  Properties:
    Service: ECS
    API: DescribeImages
    Parameters:
      RegionId: '{{ regionId }}'
      ImageName: '{{ targetImageName }}'
    DesiredValues:
    - 0
    PropertySelector: TotalCount
- Name: runInstances
  Action: ACS::ECS::RunInstances
  Description:
    en: Create a ECS instance with source image
    zh-cn: 用源鏡像建立一台ECS執行個體
  Properties:
    regionId: '{{ regionId }}'
    imageId: '{{ sourceImageId }}'
    instanceType: '{{ instanceType }}'
    securityGroupId: '{{ securityGroupId }}'
    vSwitchId: '{{ vSwitchId }}'
  Outputs:
    instanceId:
      ValueSelector: instanceIds[0]
      Type: String
- Name: installCloudAssistant
  Action: ACS::ECS::InstallCloudAssistant
  Description:
    en: Install cloud assostant for ECS instance
    zh-cn: 給執行個體安裝雲助手
  OnError: deleteInstance
  Properties:
    regionId: '{{ regionId }}'
    instanceId: '{{ runInstances.instanceId }}'
- Name: runCommand
  Action: ACS::ECS::RunCommand
  Description:
    en: Run cloud assostant command on ECS instance
    zh-cn: 在執行個體中運行雲助手命令
  OnError: deleteInstance
  Properties:
    regionId: '{{ regionId }}'
    commandContent: '{{ commandContent }}'
    commandType: '{{ commandType }}'
    instanceId: '{{ runInstances.instanceId }}'
- Name: stopInstance
  Action: ACS::ECS::StopInstance
  Description:
    en: Stops the ECS instance
    zh-cn: 停止ECS執行個體
  Properties:
    regionId: '{{ regionId }}'
    instanceId: '{{ runInstances.instanceId }}'
- Name: createImage
  Action: ACS::ECS::CreateImage
  Description:
    en: Create new image with the specified image name and instance ID
    zh-cn: 通過指定執行個體ID和鏡像名稱建立新的鏡像
  OnError: deleteInstance
  Properties:
    regionId: '{{ regionId }}'
    imageName: '{{ targetImageName }}'
    instanceId: '{{ runInstances.instanceId }}'
    tags: '{{tags}}'
  Outputs:
    imageId:
      ValueSelector: imageId
      Type: String
- Name: deleteInstance
  Action: ACS::ExecuteAPI
  Description:
    en: Deletes the ECS instance
    zh-cn: 刪除ECS執行個體
  Properties:
    Service: ECS
    API: DeleteInstance
    Risk: Normal
    Parameters:
      RegionId: '{{ regionId }}'
      InstanceId: '{{ runInstances.instanceId }}'
      Force: true
- Name: modifyScalingConfiguration
  Action: ACS::ExecuteAPI
  Description:
    en: Modify scaling configuration
    zh-cn: 修改伸縮配置
  Properties:
    Service: ESS
    API: ModifyScalingConfiguration
    Parameters:
      RegionId: '{{ regionId }}'
      ScalingConfigurationId: '{{ ACS::TaskLoopItem }}'
      ImageId: '{{ createImage.imageId }}'
  Loop:
    Items: '{{ scalingConfigurationIds }}'
Outputs:
  imageId:
    Type: String
    Value: '{{ createImage.imageId }}'