After creating an Operation Orchestration Service (OOS)-trusted role and granting the required permissions to the role, you can create a template.
This topic describes how to create a simple template for obtaining the IDs of Elastic Compute Service (ECS) instances in a specified status, such as Running or Stopped, under the current account. The template uses the OOSServiceRole role to call the DescribeInstances operation and automatically goes through the records to search for ECS instances in the specified status. If no more than 1,000 ECS instances are in the specified status, the IDs of all these ECS instances are returned. If more than 1,000 ECS instances are in the specified status, the IDs of the first 1,000 ECS instances in the specified status are returned. For more information, see Restrictions.
Procedure
Log on to the ECS console. Choose Maintenance & Monitoring > Operation Orchestration Service in the left-side navigation pane.
Click the Custom Templates tab, and then click Create Template.
In the Basic Information section, set template parameters.
- Set Template Name to DescribeInstances in this example.
In the template details section, select the YAML format and insert the following code.
Note: You can modify this template to add multiple tasks and call any API operation, as long as you have granted sufficient permissions the OOSServiceRole role.
---
Description: DescribeInstances
FormatVersion: OOS-2019-06-01
Outputs:
InstanceIds:
Type: List
Value: "{{ describeInstances.InstanceIds }}"
Parameters:
Status:
Description: Running or Stopped
Type: String
Tasks:
- Name: describeInstances
Action: ACS::ExecuteAPI
Properties:
Service: ECS
API: DescribeInstances
Parameters:
Status: "{{ Status }}"
Outputs:
InstanceIds:
Type: List
ValueSelector: .Instances.Instance[].InstanceId
Click Create Template.