創建模板
1.登陸OOS控制檯,找到我的模板,點擊創建模板。
2.選擇空白模版。
3.複製下文提供的模板到YAML欄中,輸入模板名稱,點擊創建模板
模板內容:
Description: Modify chargetype of prepaid instance charge type.
FormatVersion: OOS-2019-06-01
Parameters:
regionId:
Type: String
Description:
en: The id of region.
zh-cn: 地域ID。
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targets:
Type: Json
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
rateControl:
Description:
en: Concurrency ratio of task execution.
zh-cn: 任務執行的併發比率。
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Description:
en: The RAM role to be assumed by OOS.
zh-cn: OOS扮演的RAM角色。
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
-
Name: getInstance
Description: en: Views the ECS instances. zh-cn: 獲取ECS實例。 Action: 'ACS::SelectTargets' Properties: ResourceType: 'ALIYUN::ECS::Instance' RegionId: '{{ regionId }}' Filters:
-
'{{ targets }}'
Outputs: instanceIds:
Type: List
ValueSelector: 'Instances.Instance[].InstanceId'
-
-
Name: describeInstances
Action: 'ACS::ExecuteAPI' Description: zh-cn: Get Instance by expired time. en: 根據到期時間過濾實例。 Properties: Service: ECS API: DescribeInstances Parameters:
RegionId: '{{ regionId }}'
InstanceIds: '{{ getInstance.instanceIds }}'
InstanceChargeType: PrePaid
Filter3Key: ExpiredStartTime
Filter4Key: ExpiredEndTime
Filter3Value:
'Fn::FormatUTCTime':- 'Fn::AddHour': - '{{ACS::CurrentUTCTime}}' - 24 - '%Y-%m-%dT00:00Z'
Filter4Value:
'Fn::FormatUTCTime':- 'Fn::AddHour': - '{{ACS::CurrentUTCTime}}' - 48 - '%Y-%m-%dT00:00Z' Outputs: instanceIds:
Type: List
ValueSelector: 'Instances.Instance[].InstanceId' -
Name: modifyInstanceChargeType
Description: en: Modify instance charge type. zh-cn: 修改實例計費方式。 Action: 'ACS::ECS::ModifyInstanceChargeType' Properties: regionId: '{{ regionId }}' instanceId: '{{ ACS::TaskLoopItem }}' instanceChargeType: PostPaid Loop: RateControl: '{{ rateControl }}' Items: '{{ describeInstances.instanceIds }}'
Outputs:
InstanceIds:
Type: List
Value: '{{ describeInstances.instanceIds }}'
4、定時執行模版
找到定時運維,點擊創建,選擇週期性重複執行,設置定時執行的規則
截圖所示規則:截止規則結束時間,每天0點0分定時執行制指定模板,建議設置早上8~9點
5.模板選擇,選擇上文創建的模板
6.參數設置,設置目標地域,選擇對應的實例。點擊立即執行
7.在執行詳情頁中可以查看定時執行列表和所操作的資源