全部产品
云市场
云游戏

ACS::ExecuteAPI

更新时间:2020-01-15 14:24:41

用途

此Action可以用来调用某个云产品(如ECS)的OpenAPI。如果OpenAPI是一个异步调用,则您可以使用ACS::WaitFor来等待其资源达到预期的状态。请参考ACS::WaitFor动作。

语法

RPC风格API

说明:Tasks.Properties.API 就是云产品API的Action,所以无需在 Tasks.Properties.Parameters 中填写 Action

  • YAML格式
  1. Tasks:
  2. - Name: executeAPITaskExample
  3. Action: ACS::ExecuteAPI
  4. Properties:
  5. Service: ECS # 必填,云产品code name,即RAM ARN里面的云产品code name。大小写不敏感。如ECS, RDS, FC...
  6. API: DescribeInstances # 必填,云产品的API名称。大小写不敏感。如ECS API "DescribeInstances"
  7. AutoPaging: false # 可选,对于支持分页的OpenAPI,是否自动翻页以获取所有的结果,默认:true
  8. Parameters: # 调用OpenAPI所需要的参数,具体参考具体的API帮助
  9. Parameter1: Value1
  10. Parameter2: Value2
  11. Outputs:
  12. OutputParameter1:
  13. ValueSelector: 'jq selector' # jq的选择器语法,以OpenAPI的返回作为JSON输入,jq的语法请参考 https://stedolan.github.io/jq/
  14. Type: String/Boolean/List(Array)/Number/Object
  • JSON格式(请参考YAML注释说明)
  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

  • YAML格式
  1. Tasks:
  2. - Name: executeAPITaskExample2
  3. Action: ACS::ExecuteAPI
  4. Properties:
  5. Service: OOS # 必填,云产品code name,即RAM ARN里面的云产品code name。大小写不敏感。如OOS、ECS, RDS, FC...
  6. API: PutBucket # 必填,云产品的API名称。大小写不敏感。如OOS API "PutBucket"。
  7. Method: PUT # 必填,该API HTTP请求方法。
  8. URI: '' # 该AP对应的I统一资源标识符。
  9. Headers: # 选填,源API中请求头,定义在Headers部分,如下形式进行传递。
  10. requestHeader1: 'requestHeader1Value'
  11. Parameters: # 选填,源API中的公共参数,定义在Parameters部分,
  12. commonParameter1: 'commonParameter1Value'
  13. commonParameter2: 'commonParameter2Value'
  14. # 选填,源API中的请求元素,定义在Body部分,通过xml方式进行传递。
  15. Body: |
  16. <?xml version="1.0" encoding="UTF-8"?> <supKey1> <parameter1> Value1
  17. </parameter1> <parameter2> Value2 </parameter2> </supKey1>
  • JSON格式(请参考YAML注释说明)
  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. }

示例

RPC示例模版

以下为含ECS云产品DescribeInstances API的模版。

  • YAML格式
  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格式
  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. }

ROA示例模版

以下为含OSS云产品PutBucket API的模版。

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