用途
此Action可以用來調用某個云產品(如ECS)的OpenAPI。如果OpenAPI是一個異步調用,則您可以使用ACS::WaitFor來等待其資源達到預期的狀態。
語法
說明
Tasks.Properties.API就是云產品API的Action,所以無需在Tasks.Properties.Parameters中填寫Action。
Tasks:
- Name: executeAPITaskExample
Action: ACS::ExecuteAPI
Properties:
Service: ECS # 必填,云產品code name,即RAM ARN里面的云產品code name。大小寫不敏感。如ECS, RDS, FC...
API: DescribeInstances # 必填,云產品的API名稱。大小寫不敏感。如ECS API "DescribeInstances"
AutoPaging: false # 可選,對于支持分頁的OpenAPI,是否自動翻頁以獲取所有的結果,默認:true
Parameters: # 調用OpenAPI所需要的參數,具體參考具體的API幫助
Parameter1: Value1
Parameter2: Value2
Outputs:
OutputParameter1:
ValueSelector: 'jq selector' # jq的選擇器語法,以OpenAPI的返回作為JSON輸入,jq的語法請參考 https://stedolan.github.io/jq/
Type: String/Boolean/List(Array)/Number/Object
{
"Tasks": [
{
"Name": "executeAPITaskExample",
"Action": "ACS::ExecuteAPI",
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"AutoPaging": false,
"Parameters": {
"Parameter1": "Value1",
"Parameter2": "Value2"
}
},
"Outputs": {
"OutputParameter1": {
"ValueSelector": "jq selector",
"Type": "String/Boolean/List(Array)/Number/Object"
}
}
}
]
}
Tasks:
- Name: executeAPITaskExample2
Action: ACS::ExecuteAPI
Properties:
Service: OSS # 必填,云產品code name,即RAM ARN里面的云產品code name。大小寫不敏感。如OSS、ECS, RDS, FC...
API: PutBucket # 必填,云產品的API名稱。大小寫不敏感。如OSS API "PutBucket"。
Method: PUT # 必填,該API HTTP請求方法。
URI: '' # 該AP對應的I統一資源標識符。
Headers: # 選填,源API中請求頭,定義在Headers部分,如下形式進行傳遞。
requestHeader1: 'requestHeader1Value'
Parameters: # 選填,源API中的公共參數,定義在Parameters部分,
commonParameter1: 'commonParameter1Value'
commonParameter2: 'commonParameter2Value'
# 選填,源API中的請求元素,定義在Body部分,通過xml方式進行傳遞。
Body: |
<?xml version="1.0" encoding="UTF-8"?> <supKey1> <parameter1> Value1
</parameter1> <parameter2> Value2 </parameter2> </supKey1>
{
"Tasks": [
{
"Name": "executeAPITaskExample2",
"Action": "ACS::ExecuteAPI",
"Properties": {
"Service": "OSS",
"API": "PutBucket",
"Method": "PUT",
"URI": "",
"Headers": {
"requestHeader1": "requestHeader1Value"
},
"Parameters": {
"commonParameter1": "commonParameter1Value",
"commonParameter2": "commonParameter2Value"
},
"Body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <supKey1> <parameter1> Value1\n</parameter1> <parameter2> Value2 </parameter2> </supKey1>\n"
}
}
]
}
示例
FormatVersion: OOS-2019-06-01
Description: Views the ECS instances by specifying instance status.
Parameters:
status:
Description: The ECS instances status for query instances.
Type: String
Tasks:
- Name: describeInstances
Action: ACS::ExecuteAPI
Description: Views the ECS instances by specifying instance status.
Properties:
Service: ECS
API: DescribeInstances
Parameters:
Status: '{{ status }}'
Outputs:
instanceIds:
Type: List
ValueSelector: Instances.Instance[].InstanceId
Outputs:
instanceIds:
Type: List
Value: '{{ describeInstances.instanceIds }}'
{
"FormatVersion": "OOS-2019-06-01",
"Description": "Views the ECS instances by specifying instance status.",
"Parameters": {
"status": {
"Description": "The ECS instances status for query instances.",
"Type": "String"
}
},
"Tasks": [
{
"Name": "describeInstances",
"Action": "ACS::ExecuteAPI",
"Description": "Views the ECS instances by specifying instance status.",
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"Status": "{{ status }}"
}
},
"Outputs": {
"instanceIds": {
"Type": "List",
"ValueSelector": "Instances.Instance[].InstanceId"
}
}
}
],
"Outputs": {
"instanceIds": {
"Type": "List",
"Value": "{{ describeInstances.instanceIds }}"
}
}
}
FormatVersion: OOS-2019-06-01
Description:
en: Create multiple buckets in different region at the same time.
zh-cn: 同時創建多個不同區域的Bucket。
Parameters:
Regions:
Description:
en: The region id..
zh-cn: 區域Id。
Type: List
BucketName:
Description:
en: The bucket name.
zh-cn: Bucket名稱。
Type: String
DataRedundancyType:
Description:
en: Specifies the data disaster tolerance type of the bucket.
zh-cn: 指定Bucket的數據容災類型。
Type: String
AllowedValues:
- LRS
- ZRS
StorageClass:
Description:
en: Specify the bucket storage type.
zh-cn: 指定Bucket存儲類型。
Type: String
AllowedValues:
- Standard
- IA
- Archive
XOssAcl:
Description:
en: Specify bucket access rights.
zh-cn: 指定Bucket訪問權限。
Type: String
AllowedValues:
- public-read-write
- public-read
- private
RateControl:
Description:
en: Concurrency ratio of task execution.
zh-cn: 任務執行的并發比率。
Type: Json
AssociationProperty: RateControl
OOSAssumeRole:
Description: The RAM role to be assumed by OOS.
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: PutBucket
Action: 'ACS::ExecuteAPI'
Description:
en: Create buckets in different regions.
zh-cn: 創建不同區域的Bucket。
Properties:
Service: OSS
API: PutBucket
Method: PUT
URI: ''
Headers:
x-oss-acl: '{{ XOssAcl }}'
Parameters:
BucketName: '{{ BucketName }}-{{ACS::TaskLoopItem}}'
RegionId: '{{ACS::TaskLoopItem}}'
Body: |
<?xml version="1.0" encoding="UTF-8"?>
<CreateBucketConfiguration>
<StorageClass>{{ StorageClass }}</StorageClass>
<DataRedundancyType>{{ DataRedundancyType }}</DataRedundancyType>
</CreateBucketConfiguration>
Loop:
Items: '{{ Regions }}'
RateControl: '{{ RateControl }}'
Outputs:
imageIds:
AggregateType: 'Fn::ListJoin'
AggregateField: imageIds
Outputs:
imageIds:
Type: String
ValueSelector: .
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Create multiple buckets in different region at the same time.",
"zh-cn": "同時創建多個不同區域的Bucket。"
},
"Parameters": {
"Regions": {
"Description": {
"en": "The region id..",
"zh-cn": "區域Id。"
},
"Type": "List"
},
"BucketName": {
"Description": {
"en": "The bucket name.",
"zh-cn": "Bucket名稱。"
},
"Type": "String"
},
"DataRedundancyType": {
"Description": {
"en": "Specifies the data disaster tolerance type of the bucket.",
"zh-cn": "指定Bucket的數據容災類型。"
},
"Type": "String",
"AllowedValues": [
"LRS",
"ZRS"
]
},
"StorageClass": {
"Description": {
"en": "Specify the bucket storage type.",
"zh-cn": "指定Bucket存儲類型。"
},
"Type": "String",
"AllowedValues": [
"Standard",
"IA",
"Archive"
]
},
"XOssAcl": {
"Description": {
"en": "Specify bucket access rights.",
"zh-cn": "指定Bucket訪問權限。"
},
"Type": "String",
"AllowedValues": [
"public-read-write",
"public-read",
"private"
]
},
"RateControl": {
"Description": {
"en": "Concurrency ratio of task execution.",
"zh-cn": "任務執行的并發比率。"
},
"Type": "Json",
"AssociationProperty": "RateControl"
},
"OOSAssumeRole": {
"Description": "The RAM role to be assumed by OOS.",
"Type": "String",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{ OOSAssumeRole }}",
"Tasks": [
{
"Name": "PutBucket",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Create buckets in different regions.",
"zh-cn": "創建不同區域的Bucket。"
},
"Properties": {
"Service": "OSS",
"API": "PutBucket",
"Method": "PUT",
"URI": "",
"Headers": {
"x-oss-acl": "{{ XOssAcl }}"
},
"Parameters": {
"BucketName": "{{ BucketName }}-{{ACS::TaskLoopItem}}",
"RegionId": "{{ACS::TaskLoopItem}}"
},
"Body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<CreateBucketConfiguration>\n <StorageClass>{{ StorageClass }}</StorageClass>\n <DataRedundancyType>{{ DataRedundancyType }}</DataRedundancyType>\n</CreateBucketConfiguration>\n"
},
"Loop": {
"Items": "{{ Regions }}",
"RateControl": "{{ RateControl }}",
"Outputs": {
"imageIds": {
"AggregateType": "Fn::ListJoin",
"AggregateField": "imageIds"
}
}
},
"Outputs": {
"imageIds": {
"Type": "String",
"ValueSelector": "."
}
}
}
]
}
FormatVersion: OOS-2019-06-01
Description:
en: Perform a single ExecuteApi operation.
zh-cn: SLS 投遞日志
name-en: ACS-OOS-ExampleExecuteECSDescribeRegions
name-zh-cn: 基礎示例模板
categories:
- ops
Parameters:
regionId:
Type: String
AssociationProperty: RegionId
Description: 地域
projectName:
Type: String
Description: Project 名稱
logstoreName:
Type: String
Description: 日志庫名稱
Contents:
Type: String
Description: 日志內容
AssociationProperty: Json
Default:
- log1: value1
- log2: value2
Tags:
Type: String
Description: 日志標簽
AssociationProperty: Json
Default: []
Tasks:
- Name: SlsPutLogs
Action: ACS::ExecuteApi
Description: SLS 投遞日志
Properties:
Service: log
API: PutLogs
URI: /logstores/{{ logstoreName }}/shards/lb
Method: POST
Parameters:
RegionId: '{{ regionId }}'
projectName: '{{ projectName }}'
Logs:
Contents: '{{ Contents }}'
Tags: '{{ Tags }}'
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Perform a single ExecuteApi operation.",
"zh-cn": "SLS 投遞日志",
"name-en": "ACS-OOS-ExampleExecuteECSDescribeRegions",
"name-zh-cn": "基礎示例模板",
"categories": [
"ops"
]
},
"Parameters": {
"regionId": {
"Type": "String",
"AssociationProperty": "RegionId",
"Description": "地域"
},
"projectName": {
"Type": "String",
"Description": "Project 名稱"
},
"logstoreName": {
"Type": "String",
"Description": "日志庫名稱"
},
"Contents": {
"Type": "String",
"Description": "日志內容",
"AssociationProperty": "Json",
"Default": [
{
"log1": "value1"
},
{
"log2": "value2"
}
]
},
"Tags": {
"Type": "String",
"Description": "日志標簽",
"AssociationProperty": "Json",
"Default": []
}
},
"Tasks": [
{
"Name": "SlsPutLogs",
"Action": "ACS::ExecuteApi",
"Description": "SLS 投遞日志",
"Properties": {
"Service": "log",
"API": "PutLogs",
"URI": "/logstores/{{ logstoreName }}/shards/lb",
"Method": "POST",
"Parameters": {
"RegionId": "{{ regionId }}",
"projectName": "{{ projectName }}",
"Logs": {
"Contents": "{{ Contents }}"
},
"Tags": "{{ Tags }}"
}
}
}
]
}
文檔內容是否對您有幫助?