All Products
Search
Document Center

Acs_SelectTargets

Last Updated: Jun 11, 2020

Description

When you create an execution based on a template that does not use the ACS::SelectTargets action, you can select resources only by entering resource IDs or only by specifying resource tags during parameter setting. You are not allowed to switch the two methods unless you modify the template.
However, if you use the ACS::SelectTargets action, you can choose to select resources by entering the resource IDs or specifying the resource tags when you set parameters for the execution. In this way, you do not need to modify the template. Assume that a template needs to use Elastic Compute Service (ECS) instances and is configured with the ACS::SelectTargets action in the Tasks parameter. When you create an execution by using this template, you are allowed to select ECS instances by entering the instance IDs or specifying the instance tags during parameter setting.

Note: Currently, the ACS::SelectTargets action is applicable to ECS instances only.

Syntax

  • YAML format
  1. FormatVersion: OOS-2019-06-01
  2. Description: 'ACS::SelectTargets usage'
  3. Parameters:
  4. targets: # The name of the parameter that specifies the resources to be selected.
  5. Type: Json # The type of the parameter. Valid value: Json.
  6. AssociationProperty: Targets # The action used for the parameter. If the action is ACS::SelectTargets, the valid value is Targets.
  7. AssociationPropertyMetadata: # The description of the resourced to be selected.
  8. ResourceType: 'ALIYUN::ECS::Instance' # The type of the resources to be selected. Valid value: ALIYUN::ECS::Instance.
  9. Tasks:
  10. - Name: getInstance # The name of the task.
  11. Action: 'ACS::SelectTargets' # The action used to select resources.
  12. Properties:
  13. ResourceType: 'ALIYUN::ECS::Instance' # The type of resources to be selected.
  14. Filters: # The resources to be filtered.
  15. - '{{ targets }}' # The name of the parameter that specifies the resources to be selected.
  16. Outputs: # The output of the task.
  17. instanceIds: # The name of the output parameter.
  18. Type: List # The type of the output parameter.
  19. ValueSelector: 'Instances.Instance[].InstanceId' # The jQuery selector for selecting the required JSON data. For example, for ECS instances, the jQuery selector selects the instances returned by the DescribeInstances operation.
  • JSON format (For more information, see the parameter description for the YAML format.)
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": "ACS::SelectTargets usage",
  4. "Parameters": {
  5. "targets": {
  6. "Type": "Json",
  7. "AssociationProperty": "Targets",
  8. "AssociationPropertyMetadata": {
  9. "ResourceType": "ALIYUN::ECS::Instance"
  10. }
  11. }
  12. },
  13. "Tasks": [
  14. {
  15. "Name": "getInstance",
  16. "Action": "ACS::SelectTargets",
  17. "Properties": {
  18. "ResourceType": "ALIYUN::ECS::Instance",
  19. "Filters": [
  20. "{{ targets }}"
  21. ]
  22. },
  23. "Outputs": {
  24. "instanceIds": {
  25. "Type": "List",
  26. "ValueSelector": "Instances.Instance[].InstanceId"
  27. }
  28. }
  29. }
  30. ]
  31. }

Sample code for starting multiple ECS instances at a time

  • YAML format
  1. FormatVersion: OOS-2019-06-01
  2. Description:
  3. en: Bulky starts the ECS instances.
  4. name-en: ACS-ECS-BulkyStartInstances
  5. categories:
  6. - instance_manage
  7. Parameters:
  8. targets:
  9. Type: Json
  10. AssociationProperty: Targets
  11. AssociationPropertyMetadata:
  12. ResourceType: 'ALIYUN::ECS::Instance'
  13. rateControl:
  14. Description:
  15. en: Concurrency ratio of task execution.
  16. Type: Json
  17. AssociationProperty: RateControl
  18. Default:
  19. Mode: Concurrency
  20. MaxErrors: 0
  21. Concurrency: 10
  22. OOSAssumeRole:
  23. Description:
  24. en: The RAM role to be assumed by OOS.
  25. Type: String
  26. Default: OOSServiceRole
  27. RamRole: '{{ OOSAssumeRole }}'
  28. Tasks:
  29. - Name: getInstance
  30. Description:
  31. en: Views the ECS instances.
  32. Action: 'ACS::SelectTargets'
  33. Properties:
  34. ResourceType: 'ALIYUN::ECS::Instance'
  35. Filters:
  36. - '{{ targets }}'
  37. Outputs:
  38. instanceIds:
  39. Type: List
  40. ValueSelector: 'Instances.Instance[].InstanceId'
  41. - Name: startInstance
  42. Action: 'ACS::ECS::StartInstance'
  43. Description:
  44. en: Starts the ECS instances.
  45. Properties:
  46. instanceId: '{{ ACS::TaskLoopItem }}'
  47. Loop:
  48. RateControl: '{{ rateControl }}'
  49. Items: '{{ getInstance.instanceIds }}'
  50. Outputs:
  51. instanceIds:
  52. Type: List
  53. Value: '{{ getInstance.instanceIds }}'
  • JSON format
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": {
  4. "en": "Bulky starts the ECS instances.",
  5. "name-en": "ACS-ECS-BulkyStartInstances",
  6. "categories": [
  7. "instance_manage"
  8. ]
  9. },
  10. "Parameters": {
  11. "targets": {
  12. "Type": "Json",
  13. "AssociationProperty": "Targets",
  14. "AssociationPropertyMetadata": {
  15. "ResourceType": "ALIYUN::ECS::Instance"
  16. }
  17. },
  18. "rateControl": {
  19. "Description": {
  20. "en": "Concurrency ratio of task execution."
  21. },
  22. "Type": "Json",
  23. "AssociationProperty": "RateControl",
  24. "Default": {
  25. "Mode": "Concurrency",
  26. "MaxErrors": 0,
  27. "Concurrency": 10
  28. }
  29. },
  30. "OOSAssumeRole": {
  31. "Description": {
  32. "en": "The RAM role to be assumed by OOS."
  33. },
  34. "Type": "String",
  35. "Default": "OOSServiceRole"
  36. }
  37. },
  38. "RamRole": "{{ OOSAssumeRole }}",
  39. "Tasks": [
  40. {
  41. "Name": "getInstance",
  42. "Description": {
  43. "en": "Views the ECS instances."
  44. },
  45. "Action": "ACS::SelectTargets",
  46. "Properties": {
  47. "ResourceType": "ALIYUN::ECS::Instance",
  48. "Filters": [
  49. "{{ targets }}"
  50. ]
  51. },
  52. "Outputs": {
  53. "instanceIds": {
  54. "Type": "List",
  55. "ValueSelector": "Instances.Instance[].InstanceId"
  56. }
  57. }
  58. },
  59. {
  60. "Name": "startInstance",
  61. "Action": "ACS::ECS::StartInstance",
  62. "Description": {
  63. "en": "Starts the ECS instances."
  64. },
  65. "Properties": {
  66. "instanceId": "{{ ACS::TaskLoopItem }}"
  67. },
  68. "Loop": {
  69. "RateControl": "{{ rateControl }}",
  70. "Items": "{{ getInstance.instanceIds }}"
  71. }
  72. }
  73. ],
  74. "Outputs": {
  75. "instanceIds": {
  76. "Type": "List",
  77. "Value": "{{ getInstance.instanceIds }}"
  78. }
  79. }
  80. }