用途
此Action可以用来调用某个云产品(如ECS)的OpenAPI。如果OpenAPI是一个异步调用,则您可以使用ACS::WaitFor来等待其资源达到预期的状态。
语法
说明
Tasks.Properties.API就是云产品API的Action,所以无需在Tasks.Properties.Parameters中填写Action。
RPC风格API
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"
}
}
}
]
}
ROA风格API
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"
}
}
]
}
示例
RPC示例模板ECS云产品DescribeInstances API
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 }}"
}
}
}
ROA示例模板OSS云产品PutBucket API
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": "."
}
}
}
]
}
ROA示例模板SLS云产品PutLogs API
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 }}"
}
}
}
]
}
文档内容是否对您有帮助?