Template name
ACS-ESS-UpdateScalingConfigurationImage Updates the image of a scaling configuration
Template description
Runs commands to update an existing Elastic Compute Service (ECS) image, creates a new ECS image, and updates the image ID in scaling configurations.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
|
Parameter |
Description |
Type |
Required |
Default value |
Limit |
|
sourceImageId |
The source image ID. |
String |
Yes |
||
|
securityGroupId |
The security group ID. |
String |
Yes |
||
|
vSwitchId |
The vSwitch ID. |
String |
Yes |
||
|
commandContent |
The content of the Cloud Assistant commands. |
String |
Yes |
||
|
scalingConfigurationIds |
The IDs of the scaling configurations to be modified. |
List |
Yes |
||
|
regionId |
The region ID. |
String |
No |
{{ ACS::RegionId }} |
|
|
targetImageName |
The name of the new image. |
String |
No |
UpdateImage_from_{{ sourceImageId }}_on_{{ ACS::ExecutionId }} |
|
|
instanceType |
The ECS instance type. |
String |
No |
ecs.g5.large |
The value must match the regular expression: ecs\.[A-Za-z0-9\.\-]* |
|
commandType |
The type of the Cloud Assistant commands. |
String |
No |
RunShellScript |
|
|
tags |
The image tags. |
Json |
No |
[] |
|
|
OOSAssumeRole |
The Resource Access Management (RAM) role assumed by CloudOps Orchestration Service (OOS). |
String |
No |
"" |
Output parameters
|
Parameter |
Description |
Type |
|
imageId |
String |
Policy required to execute the template
{
"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"
}
]
}
Details
ACS-ESS-UpdateScalingConfigurationImage
Template content
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
name-en: ACS-ESS-UpdateScalingConfigurationImage
categories:
- elastic_manage
Parameters:
regionId:
Type: String
Label:
en: RegionId
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targetImageName:
Label:
en: NewImageName
Type: String
Default: UpdateImage_from_{{ sourceImageId }}_on_{{ ACS::ExecutionId }}
sourceImageId:
Label:
en: SourceImageId
Type: String
AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
AssociationPropertyMetadata:
RegionId: regionId
instanceType:
Label:
en: InstanceType
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AllowedPattern: ecs\.[A-Za-z0-9\.\-]*
Default: 'ecs.g5.large'
securityGroupId:
Label:
en: SecurityGroupId
Type: String
AssociationProperty: 'ALIYUN::ECS::SecurityGroup::SecurityGroupId'
AssociationPropertyMetadata:
RegionId: regionId
vSwitchId:
Label:
en: VSwitchId
Type: String
AssociationProperty: 'ALIYUN::VPC::VSwitch::VSwitchId'
AssociationPropertyMetadata:
RegionId: regionId
Filters:
- SecurityGroupId: securityGroupId
commandType:
Label:
en: CommandType
Type: String
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
commandContent:
Label:
en: CommandContent
Type: String
AssociationProperty: Code
scalingConfigurationIds:
Label:
en: ScalingConfigurationIds
Type: List
tags:
Label:
en: ImageTags
Type: Json
AssociationProperty: Tags
AssociationPropertyMetadata:
ShowSystem: false
Default: []
OOSAssumeRole:
Label:
en: OOSAssumeRole
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: checkNewImageName
Action: ACS::CheckFor
Description:
en: Check image name is available
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
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
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ runInstances.instanceId }}'
- Name: runCommand
Action: ACS::ECS::RunCommand
Description:
en: Run cloud assostant command on ECS instance
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
commandContent: '{{ commandContent }}'
commandType: '{{ commandType }}'
instanceId: '{{ runInstances.instanceId }}'
- Name: stopInstance
Action: ACS::ECS::StopInstance
Description:
en: Stops the ECS instance
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
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
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
Properties:
Service: ESS
API: ModifyScalingConfiguration
Parameters:
RegionId: '{{ regionId }}'
ScalingConfigurationId: '{{ ACS::TaskLoopItem }}'
ImageId: '{{ createImage.imageId }}'
Loop:
Items: '{{ scalingConfigurationIds }}'
Outputs:
imageId:
Type: String
Value: '{{ createImage.imageId }}'