All Products
Search
Document Center

CloudOps Orchestration Service:ACS::SelectTargets

Last Updated:Sep 11, 2024

The ACS::SelectTargets action allows you to select multiple resources at a time when you create an execution.

Description

If you create an execution based on a template that uses the ACS::SelectTargets action and in which the AssociationProperty parameter is set to Targets, you can switch among the methods to select resources without modifying the template. When you create an execution, you can select multiple resources at a time by using one of the following methods: selecting specific resources, specifying resource tags, selecting all resources, uploading a CSV file that contains resource IDs, and specifying an inventory.

selecttargets

Syntax

FormatVersion: OOS-2019-06-01
Description: 'ACS::SelectTargets usage'
Parameters:
  targets:  # The name of the parameter that specifies the resources to be selected. 
    Type: Json  # The type of the parameter. Set the value to Json. 
    AssociationProperty: Targets    # The action used for the parameter. If the action is ACS::SelectTargets, set the value to Targets. 
    AssociationPropertyMetadata:  # The description of the resources to be selected. 
      ResourceType: ALIYUN::ECS::Instance # The type of the resources to be selected. 
                    # ALIYUN::ECS::Instance The resources are Elastic Compute Service (ECS) instances.
                    # ALIYUN::ECD::Desktop The resources are for Elastic Desktop Service (EDS).
                    # ALIYUN::RDS::Instance The resources are ApsaraDB RDS instances.
                    # ALIYUN::Redis::Instance The resources are ApsaraDB for Redis instances.
                    # ALIYUN::MongoDB::Instance The resources are ApsaraDB for MongoDB instances.
                    # ALIYUN::ECS::ManagedInstance The resources are managed ECS instances.
                    # ALIYUN::ComputeNestSupplier::Instance The resources are Compute Nest service instances.
Tasks:
  - Name: getInstance # The name of the task. 
    Action: 'ACS::SelectTargets'  # The action used to select resources. 
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'  # The type of the resources to be selected. 
      Filters: # The resources to be filtered. 
        - '{{ targets }}'  # The name of the parameter that specifies the resources to be selected. 
    Outputs:  # The output of the task. 
      instanceIds: # The name of the output parameter. 
        Type: List  # The type of the output parameter. 
        ValueSelector: 'Instances.Instance[].InstanceId'  # The jQuery selector used to select the required JSON data. For example, for ECS instances, the jQuery selector selects the instances returned by the DescribeInstances operation.
{
  "FormatVersion": "OOS-2019-06-01",
  "Description": "ACS::SelectTargets usage",
  "Parameters": {
    "targets": {
      "Type": "Json",
      "AssociationProperty": "Targets",
      "AssociationPropertyMetadata": {
        "ResourceType": "ALIYUN::ECS::Instance"
      }
    }
  },
  "Tasks": [
    {
      "Name": "getInstance",
      "Action": "ACS::SelectTargets",
      "Properties": {
        "ResourceType": "ALIYUN::ECS::Instance",
        "Filters": [
          "{{ targets }}"
        ]
      },
      "Outputs": {
        "instanceIds": {
          "Type": "List",
          "ValueSelector": "Instances.Instance[].InstanceId"
        }
      }
    }
  ]
}

Sample templates

  • Sample code for starting multiple ECS instances at a time

    FormatVersion: OOS-2019-06-01
    Description:
      en: Bulky starts the ECS instances.
       
      name-en: ACS-ECS-BulkyStartInstances
       
      categories:
        - instance_manage
    Parameters:
      targets:
        Type: Json
        AssociationProperty: Targets
        AssociationPropertyMetadata:
          ResourceType: 'ALIYUN::ECS::Instance'
      rateControl:
        Description:
          en: Concurrency ratio of task execution.
           
        Type: Json
        AssociationProperty: RateControl
        Default:
          Mode: Concurrency
          MaxErrors: 0
          Concurrency: 10
      OOSAssumeRole:
        Description:
          en: The RAM role to be assumed by OOS.
           
        Type: String
        Default: OOSServiceRole
    RamRole: '{{ OOSAssumeRole }}'
    Tasks:
      - Name: getInstance
        Description:
          en: Views the ECS instances.
           
        Action: 'ACS::SelectTargets'
        Properties:
          ResourceType: 'ALIYUN::ECS::Instance'
          Filters:
            - '{{ targets }}'
        Outputs:
          instanceIds:
            Type: List
            ValueSelector: 'Instances.Instance[].InstanceId'
      - Name: startInstance
        Action: 'ACS::ECS::StartInstance'
        Description:
          en: Starts the ECS instances.
           
        Properties:
          instanceId: '{{ ACS::TaskLoopItem }}'
        Loop:
          RateControl: '{{ rateControl }}'
          Items: '{{ getInstance.instanceIds }}'
    Outputs:
      instanceIds:
        Type: List
        Value: '{{ getInstance.instanceIds }}'
    {
      "FormatVersion": "OOS-2019-06-01",
      "Description": {
        "en": "Bulky starts the ECS instances.",
         
        "name-en": "ACS-ECS-BulkyStartInstances",
         
        "categories": [
          "instance_manage"
        ]
      },
      "Parameters": {
        "targets": {
          "Type": "Json",
          "AssociationProperty": "Targets",
          "AssociationPropertyMetadata": {
            "ResourceType": "ALIYUN::ECS::Instance"
          }
        },
        "rateControl": {
          "Description": {
            "en": "Concurrency ratio of task execution.",
             
          },
          "Type": "Json",
          "AssociationProperty": "RateControl",
          "Default": {
            "Mode": "Concurrency",
            "MaxErrors": 0,
            "Concurrency": 10
          }
        },
        "OOSAssumeRole": {
          "Description": {
            "en": "The RAM role to be assumed by OOS.",
             
          },
          "Type": "String",
          "Default": "OOSServiceRole"
        }
      },
      "RamRole": "{{ OOSAssumeRole }}",
      "Tasks": [
        {
          "Name": "getInstance",
          "Description": {
            "en": "Views the ECS instances.",
             
          },
          "Action": "ACS::SelectTargets",
          "Properties": {
            "ResourceType": "ALIYUN::ECS::Instance",
            "Filters": [
              "{{ targets }}"
            ]
          },
          "Outputs": {
            "instanceIds": {
              "Type": "List",
              "ValueSelector": "Instances.Instance[].InstanceId"
            }
          }
        },
        {
          "Name": "startInstance",
          "Action": "ACS::ECS::StartInstance",
          "Description": {
            "en": "Starts the ECS instances.",
             
          },
          "Properties": {
            "instanceId": "{{ ACS::TaskLoopItem }}"
          },
          "Loop": {
            "RateControl": "{{ rateControl }}",
            "Items": "{{ getInstance.instanceIds }}"
          }
        }
      ],
      "Outputs": {
        "instanceIds": {
          "Type": "List",
          "Value": "{{ getInstance.instanceIds }}"
        }
      }
    }

Sample settings of the targets parameter for selecting ECS instances by using different methods

  • Specify ECS instance IDs

    targets:
      Type: ResourceIds
      RegionId: cn-hangzhou
      ResourceIds:
        - i-******************1
        - i-******************2
        - i-******************3
    {
      "targets": {
        "Type": "ResourceIds",
        "RegionId": "cn-hangzhou",
        "ResourceIds": [
          "i-******************1",
          "i-******************2",
          "i-******************3"
        ]
      }
    }
  • Specify ECS instance tags

    targets:
      Type: Tags
      RegionId: cn-hangzhou
      Tags:
        - Key: key1
          Value: value1
        - Key: key2
          Value: value2
    {
      "targets": {
        "Type": "Tags",
        "RegionId": "cn-hangzhou",
        "Tags": [
          {
            "Key": "key1",
            "Value": "value1"
          },
          {
            "Key": "key2",
            "Value": "value2"
          }
        ]
      }
    }
  • Specify a resource group

    targets:
      Type: ResourceGroup
      RegionId: cn-hangzhou
      ResourceGroupId: rg-acf*********re3y
    {
      "targets": {
        "Type": "ResourceGroup",
        "RegionId": "cn-hangzhou",
        "ResourceGroupId": "rg-acf*********re3y"
      }
    }
  • Select all ECS instances

    targets:
      Type: All
      RegionId: cn-hangzhou
      Parameters:
        RegionId: cn-hangzhou
        Status: Running
        Tags:
          - Key: key1
            Value: value1
    {
      "targets": {
        "Type": "All",
        "RegionId": "cn-hangzhou",
        "Parameters": {
          "RegionId": "cn-hangzhou",
          "Status": "Running",
          "Tags": [
            {
              "Key": "key1",
              "Value": "value1"
            }
          ]
        }
      }
    }
  • Specify an inventory

    targets:
        Type: Inventory
        RegionId: cn-hangzhou
        InventoryFilters:
          - Name: TypeName
            Operator: Equal
            Value:
              - ACS:InstanceInformation
          - Name: ACS:InstanceInformation.Status
            Value:
              - Running
            Operator: Equal
    {
      "targets": {
        "Type": "Inventory",
        "RegionId": "cn-hangzhou",
        "InventoryFilters": [
          {
            "Name": "TypeName",
            "Operator": "Equal",
            "Value": [
              "ACS:InstanceInformation"
            ]
          },
          {
            "Name": "ACS:InstanceInformation.Status",
            "Value": [
              "Running"
            ],
            "Operator": "Equal"
          }
        ]
      }
    }

Sample settings of the targets parameter for selecting Compute Nest service instances

  • Sample templates

    FormatVersion: OOS-2019-06-01
    Parameters:
      RegionId:
        Type: String
        Label:
          en: RegionId
           
        AssociationProperty: RegionId
        Default: '{{ ACS::RegionId }}'
      Targets:
        Type: Json
        Label:
          en: TargetInstance
           
        AssociationProperty: Targets
        AssociationPropertyMetadata:
          ResourceType: ALIYUN::ComputeNestSupplier::Instance
          RegionId: RegionId
      RateControl:
        Label:
          en: RateControl
           
        Type: Json
        AssociationProperty: RateControl
        Default:
          Mode: Concurrency
          MaxErrors: 0
          Concurrency: 1
      OOSAssumeRole:
        Label:
          en: OOSAssumeRole
           
        Type: String
    RamRole: '{{ OOSAssumeRole }}'
    Tasks:
      - Name: GetServiceInstance
        Description:
          en: Views the compute nest supplier instances
           
        Action: ACS::SelectTargets
        Properties:
          ResourceType: ALIYUN::ComputeNestSupplier::Instance
          RegionId: '{{ RegionId }}'
          Filters:
            - '{{ Targets }}'
        Outputs:
          InstanceIds:
            Type: List
            ValueSelector: ServiceInstances[].ServiceInstanceId
    Metadata:
      ALIYUN::OOS::Interface:
        ParameterGroups:
          - Parameters:
              - RegionId
              - Targets
            Label:
              default:
                 
                en: Configure Parameters
          - Parameters:
              - RateControl
              - OOSAssumeRole
            Label:
              default:
                 
                en: Control Options
    {
      "FormatVersion": "OOS-2019-06-01",
      "Parameters": {
        "RegionId": {
          "Type": "String",
          "Label": {
            "en": "RegionId",
             
          },
          "AssociationProperty": "RegionId",
          "Default": "{{ ACS::RegionId }}"
        },
        "Targets": {
          "Type": "Json",
          "Label": {
            "en": "TargetInstance",
             
          },
          "AssociationProperty": "Targets",
          "AssociationPropertyMetadata": {
            "ResourceType": "ALIYUN::ComputeNestSupplier::Instance",
            "RegionId": "RegionId"
          }
        },
        "RateControl": {
          "Label": {
            "en": "RateControl",
             
          },
          "Type": "Json",
          "AssociationProperty": "RateControl",
          "Default": {
            "Mode": "Concurrency",
            "MaxErrors": 0,
            "Concurrency": 1
          }
        },
        "OOSAssumeRole": {
          "Label": {
            "en": "OOSAssumeRole",
             
          },
          "Type": "String"
        }
      },
      "RamRole": "{{ OOSAssumeRole }}",
      "Tasks": [
        {
          "Name": "GetServiceInstance",
          "Description": {
            "en": "Views the compute nest supplier instances",
             
          },
          "Action": "ACS::SelectTargets",
          "Properties": {
            "ResourceType": "ALIYUN::ComputeNestSupplier::Instance",
            "RegionId": "{{ RegionId }}",
            "Filters": [
              "{{ Targets }}"
            ]
          },
          "Outputs": {
            "InstanceIds": {
              "Type": "List",
              "ValueSelector": "ServiceInstances[].ServiceInstanceId"
            }
          }
        }
      ],
      "Metadata": {
        "ALIYUN::OOS::Interface": {
          "ParameterGroups": [
            {
              "Parameters": [
                "RegionId",
                "Targets"
              ],
              "Label": {
                "default": {
                   
                  "en": "Configure Parameters"
                }
              }
            },
            {
              "Parameters": [
                "RateControl",
                "OOSAssumeRole"
              ],
              "Label": {
                "default": {
                   
                  "en": "Control Options"
                }
              }
            }
          ]
        }
      }
    }
  • Specify instance IDs

    targets:
      ResourceIds:
        - si-9b136xxxxxxxxxxxxxxx
        - si-f63edxxxxxxxxxxxxxxx
      RegionId: cn-hangzhou
      Type: ResourceIds
    {
      "targets": {
        "ResourceIds": [
          "si-9b1363ae63664f19a156",
          "si-f63ed519cc3445eebdcd"
        ],
        "RegionId": "cn-hangzhou",
        "Type": "ResourceIds"
      }
    }
  • Select all service instances that are deployed in the China (Hangzhou) region and whose service IDs are in the service-xxxx format and whose service version is 4.

    targets:
      Type: All
      RegionId: cn-hangzhou
      Parameters:
        Filter:
          - Status: Deployed
            Version: '4'
            RegionId: cn-hangzhou
            ServiceId: service-xxxx
    {
    	"targets": {
    		"Type": "All",
    		"RegionId": "cn-hangzhou",
    		"Parameters": {
    			"Filter": [{
    				"Status": "Deployed",
    				"Version": "4",
    				"RegionId": "cn-hangzhou",
    				"ServiceId": "service-xxxx"
    			}]
    		}
    	}
    }