All Products
Search
Document Center

ACS__ ExecuteAPI

Last Updated: Jun 11, 2020

Description

The ACS::ExecuteAPI action can be used to call an API operation of a cloud service such as Elastic Compute Service (ECS). If the API operation is called asynchronously, you can use the ACS: WaitFor action to wait for the specified instance to enter the expected state. For more information, see ACS::WaitFor.

Syntax

RPC API operations

Note: In the Properties parameter of the Tasks parameter, the API parameter specifies the API operation to be called, so you do not need to specify it again in the Parameters parameter.

  • YAML format
  1. Tasks:
  2. - Name: executeAPITaskExample
  3. Action: ACS::ExecuteAPI
  4. Properties:
  5. Service: ECS # Required. The Alibaba Cloud Resource Name (ARN) of the cloud service in Resource Access Management (RAM). The name is case insensitive, such as ECS, RDS, and FC.
  6. API: DescribeInstances # Required. The name of an API operation of the cloud service. The name is case insensitive, such as DescribeInstances.
  7. AutoPaging: false # Optional. Specifies whether to automatically go through pages to obtain all results for API operations that return results on different pages. Default value: true.
  8. Parameters: # The parameters required for calling an API operation. For more information, see the relevant documentation.
  9. Parameter1: Value1
  10. Parameter2: Value2
  11. Outputs:
  12. OutputParameter1:
  13. ValueSelector: 'jq selector' # The jQuery selector for selecting the required JSON data. For example, when you call an API operation for a task, the jQuery selector extracts the required information from the returned JSON data. For more information, see https://stedolan.github.io/jq/.
  14. Type: String/Boolean/List(Array)/Number/Object
  • JSON format (For more information, see the parameter description for the YAML format.)
  1. {
  2. "Tasks": [
  3. {
  4. "Name": "executeAPITaskExample",
  5. "Action": "ACS::ExecuteAPI",
  6. "Properties": {
  7. "Service": "ECS",
  8. "API": "DescribeInstances",
  9. "AutoPaging": false,
  10. "Parameters": {
  11. "Parameter1": "Value1",
  12. "Parameter2": "Value2"
  13. }
  14. },
  15. "Outputs": {
  16. "OutputParameter1": {
  17. "ValueSelector": "jq selector",
  18. "Type": "String/Boolean/List(Array)/Number/Object"
  19. }
  20. }
  21. }
  22. ]
  23. }

ROA API operations

  • YAML format
  1. Tasks:
  2. - Name: executeAPITaskExample2
  3. Action: ACS::ExecuteAPI
  4. Properties:
  5. Service: OOS # Required. The ARN of the cloud service in RAM. The name is case insensitive, such as OOS, ECS, RDS, and FC.
  6. API: PutBucket # Required. The name of an API operation of the cloud service. The name is case insensitive, such as PutBucket.
  7. Method: PUT # Required. The HTTP request method of the API operation.
  8. URI: '' # The URI used by the API operation.
  9. Headers: # Optional. The request header of the API operation. Set this parameter as follows:
  10. requestHeader1: 'requestHeader1Value'
  11. Parameters: # Optional. The common parameters of the API operation.
  12. commonParameter1: 'commonParameter1Value'
  13. commonParameter2: 'commonParameter2Value'
  14. # Optional. The request elements of the API operation. Set this parameter in the XML format.
  15. Body: |
  16. <?xml version="1.0" encoding="UTF-8"?> <supKey1> <parameter1> Value1
  17. </parameter1> <parameter2> Value2 </parameter2> </supKey1>
  • JSON format (For more information, see the parameter description for the YAML format.)
  1. {
  2. "Tasks": [
  3. {
  4. "Name": "executeAPITaskExample2",
  5. "Action": "ACS::ExecuteAPI",
  6. "Properties": {
  7. "Service": "OOS",
  8. "API": "PutBucket",
  9. "Method": "PUT",
  10. "URI": "",
  11. "Headers": {
  12. "requestHeader1": "requestHeader1Value"
  13. },
  14. "Parameters": {
  15. "commonParameter1": "commonParameter1Value",
  16. "commonParameter2": "commonParameter2Value"
  17. },
  18. "Body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <supKey1> <parameter1> Value1\n</parameter1> <parameter2> Value2 </parameter2> </supKey1>\n"
  19. }
  20. }
  21. ]
  22. }

Sample code

Sample code for calling RPC API operations

The following is the sample code for calling the ECS API operation DescribeInstances:

  • YAML format
  1. FormatVersion: OOS-2019-06-01
  2. Description: Views the ECS instances by specifying instance status.
  3. Parameters:
  4. status:
  5. Description: The ECS instances status for query instances.
  6. Type: String
  7. Tasks:
  8. - Name: describeInstances
  9. Action: ACS::ExecuteAPI
  10. Description: Views the ECS instances by specifying instance status.
  11. Properties:
  12. Service: ECS
  13. API: DescribeInstances
  14. Parameters:
  15. Status: '{{ status }}'
  16. Outputs:
  17. instanceIds:
  18. Type: List
  19. ValueSelector: Instances.Instance[].InstanceId
  20. Outputs:
  21. instanceIds:
  22. Type: List
  23. Value: '{{ describeInstances.instanceIds }}'
  • JSON format
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": "Views the ECS instances by specifying instance status.",
  4. "Parameters": {
  5. "status": {
  6. "Description": "The ECS instances status for query instances.",
  7. "Type": "String"
  8. }
  9. },
  10. "Tasks": [
  11. {
  12. "Name": "describeInstances",
  13. "Action": "ACS::ExecuteAPI",
  14. "Description": "Views the ECS instances by specifying instance status.",
  15. "Properties": {
  16. "Service": "ECS",
  17. "API": "DescribeInstances",
  18. "Parameters": {
  19. "Status": "{{ status }}"
  20. }
  21. },
  22. "Outputs": {
  23. "instanceIds": {
  24. "Type": "List",
  25. "ValueSelector": "Instances.Instance[].InstanceId"
  26. }
  27. }
  28. }
  29. ],
  30. "Outputs": {
  31. "instanceIds": {
  32. "Type": "List",
  33. "Value": "{{ describeInstances.instanceIds }}"
  34. }
  35. }
  36. }

Sample code for calling ROA API operations

The following is the sample code for calling the OSS API operation PutBucket.

  • YAML format
  1. FormatVersion: OOS-2019-06-01
  2. Description:
  3. en: Create multiple buckets in different region at the same time.
  4. Parameters:
  5. Regions:
  6. Description:
  7. en: The region id..
  8. Type: List
  9. BucketName:
  10. Description:
  11. en: The bucket name.
  12. Type: String
  13. DataRedundancyType:
  14. Description:
  15. en: Specifies the data disaster tolerance type of the bucket.
  16. Type: String
  17. AllowedValues:
  18. - LRS
  19. - ZRS
  20. StorageClass:
  21. Description:
  22. en: Specify the bucket storage type.
  23. Type: String
  24. AllowedValues:
  25. - Standard
  26. - IA
  27. - Archive
  28. XOssAcl:
  29. Description:
  30. en: Specify bucket access rights.
  31. Type: String
  32. AllowedValues:
  33. - public-read-write
  34. - public-read
  35. - private
  36. RateControl:
  37. Description:
  38. en: Concurrency ratio of task execution.
  39. Type: Json
  40. AssociationProperty: RateControl
  41. OOSAssumeRole:
  42. Description: The RAM role to be assumed by OOS.
  43. Type: String
  44. Default: OOSServiceRole
  45. RamRole: '{{ OOSAssumeRole }}'
  46. Tasks:
  47. - Name: PutBucket
  48. Action: 'ACS::ExecuteAPI'
  49. Description:
  50. en: Create buckets in different regions.
  51. Properties:
  52. Service: OSS
  53. API: PutBucket
  54. Method: PUT
  55. URI: ''
  56. Headers:
  57. x-oss-acl: '{{ XOssAcl }}'
  58. Parameters:
  59. BucketName: '{{ BucketName }}-{{ACS::TaskLoopItem}}'
  60. RegionId: '{{ACS::TaskLoopItem}}'
  61. Body: |
  62. <?xml version="1.0" encoding="UTF-8"?>
  63. <CreateBucketConfiguration>
  64. <StorageClass>{{ StorageClass }}</StorageClass>
  65. <DataRedundancyType>{{ DataRedundancyType }}</DataRedundancyType>
  66. </CreateBucketConfiguration>
  67. Loop:
  68. Items: '{{ Regions }}'
  69. RateControl: '{{ RateControl }}'
  70. Outputs:
  71. imageIds:
  72. AggregateType: 'Fn::ListJoin'
  73. AggregateField: imageIds
  74. Outputs:
  75. imageIds:
  76. Type: String
  77. ValueSelector: .
  • JSON format
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": {
  4. "en": "Create multiple buckets in different region at the same time."
  5. },
  6. "Parameters": {
  7. "Regions": {
  8. "Description": {
  9. "en": "The region id.."
  10. },
  11. "Type": "List"
  12. },
  13. "BucketName": {
  14. "Description": {
  15. "en": "The bucket name."
  16. },
  17. "Type": "String"
  18. },
  19. "DataRedundancyType": {
  20. "Description": {
  21. "en": "Specifies the data disaster tolerance type of the bucket."
  22. },
  23. "Type": "String",
  24. "AllowedValues": [
  25. "LRS",
  26. "ZRS"
  27. ]
  28. },
  29. "StorageClass": {
  30. "Description": {
  31. "en": "Specify the bucket storage type."
  32. },
  33. "Type": "String",
  34. "AllowedValues": [
  35. "Standard",
  36. "IA",
  37. "Archive"
  38. ]
  39. },
  40. "XOssAcl": {
  41. "Description": {
  42. "en": "Specify bucket access rights."
  43. },
  44. "Type": "String",
  45. "AllowedValues": [
  46. "public-read-write",
  47. "public-read",
  48. "private"
  49. ]
  50. },
  51. "RateControl": {
  52. "Description": {
  53. "en": "Concurrency ratio of task execution."
  54. },
  55. "Type": "Json",
  56. "AssociationProperty": "RateControl"
  57. },
  58. "OOSAssumeRole": {
  59. "Description": "The RAM role to be assumed by OOS.",
  60. "Type": "String",
  61. "Default": "OOSServiceRole"
  62. }
  63. },
  64. "RamRole": "{{ OOSAssumeRole }}",
  65. "Tasks": [
  66. {
  67. "Name": "PutBucket",
  68. "Action": "ACS::ExecuteAPI",
  69. "Description": {
  70. "en": "Create buckets in different regions."
  71. },
  72. "Properties": {
  73. "Service": "OSS",
  74. "API": "PutBucket",
  75. "Method": "PUT",
  76. "URI": "",
  77. "Headers": {
  78. "x-oss-acl": "{{ XOssAcl }}"
  79. },
  80. "Parameters": {
  81. "BucketName": "{{ BucketName }}-{{ACS::TaskLoopItem}}",
  82. "RegionId": "{{ACS::TaskLoopItem}}"
  83. },
  84. "Body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<CreateBucketConfiguration>\n <StorageClass>{{ StorageClass }}</StorageClass>\n <DataRedundancyType>{{ DataRedundancyType }}</DataRedundancyType>\n</CreateBucketConfiguration>\n"
  85. },
  86. "Loop": {
  87. "Items": "{{ Regions }}",
  88. "RateControl": "{{ RateControl }}",
  89. "Outputs": {
  90. "imageIds": {
  91. "AggregateType": "Fn::ListJoin",
  92. "AggregateField": "imageIds"
  93. }
  94. }
  95. },
  96. "Outputs": {
  97. "imageIds": {
  98. "Type": "String",
  99. "ValueSelector": "."
  100. }
  101. }
  102. }
  103. ]
  104. }