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
Tasks:
- Name: executeAPITaskExample
Action: ACS::ExecuteAPI
Properties:
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.
API: DescribeInstances # Required. The name of an API operation of the cloud service. The name is case insensitive, such as DescribeInstances.
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.
Parameters: # The parameters required for calling an API operation. For more information, see the relevant documentation.
Parameter1: Value1
Parameter2: Value2
Outputs:
OutputParameter1:
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/.
Type: String/Boolean/List(Array)/Number/Object
JSON format (For more information, see the parameter description for the YAML format.)
{
"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 operations
YAML format
Tasks:
- Name: executeAPITaskExample2
Action: ACS::ExecuteAPI
Properties:
Service: OOS # Required. The ARN of the cloud service in RAM. The name is case insensitive, such as OOS, ECS, RDS, and FC.
API: PutBucket # Required. The name of an API operation of the cloud service. The name is case insensitive, such as PutBucket.
Method: PUT # Required. The HTTP request method of the API operation.
URI: '' # The URI used by the API operation.
Headers: # Optional. The request header of the API operation. Set this parameter as follows:
requestHeader1: 'requestHeader1Value'
Parameters: # Optional. The common parameters of the API operation.
commonParameter1: 'commonParameter1Value'
commonParameter2: 'commonParameter2Value'
# Optional. The request elements of the API operation. Set this parameter in the XML format.
Body: |
<?xml version="1.0" encoding="UTF-8"?> <supKey1> <parameter1> Value1
</parameter1> <parameter2> Value2 </parameter2> </supKey1>
JSON format (For more information, see the parameter description for the YAML format.)
{
"Tasks": [
{
"Name": "executeAPITaskExample2",
"Action": "ACS::ExecuteAPI",
"Properties": {
"Service": "OOS",
"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"
}
}
]
}
Sample code
Sample code for calling RPC API operations
The following is the sample code for calling the ECS API operation DescribeInstances:
YAML format
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 }}'
JSON format
{
"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 }}"
}
}
}
Sample code for calling ROA API operations
The following is the sample code for calling the OSS API operation PutBucket.
YAML format
FormatVersion: OOS-2019-06-01
Description:
en: Create multiple buckets in different region at the same time.
Parameters:
Regions:
Description:
en: The region id..
Type: List
BucketName:
Description:
en: The bucket name.
Type: String
DataRedundancyType:
Description:
en: Specifies the data disaster tolerance type of the bucket.
Type: String
AllowedValues:
- LRS
- ZRS
StorageClass:
Description:
en: Specify the bucket storage type.
Type: String
AllowedValues:
- Standard
- IA
- Archive
XOssAcl:
Description:
en: Specify bucket access rights.
Type: String
AllowedValues:
- public-read-write
- public-read
- private
RateControl:
Description:
en: Concurrency ratio of task execution.
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.
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: .
JSON format
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Create multiple buckets in different region at the same time."
},
"Parameters": {
"Regions": {
"Description": {
"en": "The region id.."
},
"Type": "List"
},
"BucketName": {
"Description": {
"en": "The bucket name."
},
"Type": "String"
},
"DataRedundancyType": {
"Description": {
"en": "Specifies the data disaster tolerance type of the bucket."
},
"Type": "String",
"AllowedValues": [
"LRS",
"ZRS"
]
},
"StorageClass": {
"Description": {
"en": "Specify the bucket storage type."
},
"Type": "String",
"AllowedValues": [
"Standard",
"IA",
"Archive"
]
},
"XOssAcl": {
"Description": {
"en": "Specify bucket access rights."
},
"Type": "String",
"AllowedValues": [
"public-read-write",
"public-read",
"private"
]
},
"RateControl": {
"Description": {
"en": "Concurrency ratio of task execution."
},
"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."
},
"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": "."
}
}
}
]
}