Description
L'action ACS::ExecuteAPI permet d'appeler une opération d'API pour un service cloud tel que Elastic Compute Service (ECS). Si l'appel à l'opération d'API est asynchrone, utilisez l'action ACS::WaitFor pour attendre que la ressource spécifiée atteigne l'état attendu.
Syntaxe
L'attribut Tasks.Properties.API spécifie l'opération d'API à appeler ; il n'est donc pas nécessaire de la spécifier à nouveau dans l'attribut Tasks.Properties.Parameters.
Opérations d'API RPC
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 not case-sensitive, such as ECS, RDS, or FC.
API: DescribeInstances # Required. The name of an API operation of the cloud service. The name is not case-sensitive, 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 that are required for calling the API operation. For more information, see the relevant documentation.
Parameter1: Value1
Parameter2: Value2
Outputs:
OutputParameter1:
ValueSelector: 'jq selector' # The jQuery selector for selecting the data to return. The jQuery selector extracts information from the JSON data returned by the API operation. For more information about the jQuery syntax, visit 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"
}
}
}
]
}Opérations d'API ROA
Tasks:
- Name: executeAPITaskExample2
Action: ACS::ExecuteAPI
Properties:
Service: OSS # Required. The ARN of the cloud service in RAM. The name is not case-sensitive, such as OSS, ECS, RDS, or FC.
API: PutBucket # Required. The name of an API operation of the cloud service. The name is not case-sensitive, such as PutBucket.
Method: PUT # Required. The HTTP request method of the API operation.
URI: '' # The Uniform Resource Identifier (URI) that is used by the API operation.
Headers: # Optional. The request headers of the API operation. Specify this attribute in the following format:
requestHeader1: 'requestHeader1Value'
Parameters: # Optional. The common parameters of the API operation.
commonParameter1: 'commonParameter1Value'
commonParameter2: 'commonParameter2Value'
# Optional. The request body of the API operation. Specify this attribute in the XML format.
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"
}
}
]
}Exemples
Appeler l'opération DescribeInstances d'ECS au format RPC
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 }}"
}
}
}Appeler l'opération PutBucket d'Object Storage Service (OSS) au format ROA
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: .{
"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": "."
}
}
}
]
}Appeler l'opération PutLogs de Simple Log Service au format ROA
FormatVersion: OOS-2019-06-01
Description:
en: Perform a single ExecuteApi operation.
name-en: ACS-OOS-ExampleExecuteECSDescribeRegions
categories:
- ops
Parameters:
regionId:
Type: String
AssociationProperty: RegionId
Description: The ID of the region.
projectName:
Type: String
Description: The name of the project.
logstoreName:
Type: String
Description: The name of the Logstore.
Contents:
Type: String
Description: The content of the logs.
AssociationProperty: Json
Default:
- log1: value1
- log2: value2
Tags:
Type: String
Description: The tags that are added to the logs.
AssociationProperty: Json
Default: []
Tasks:
- Name: SlsPutLogs
Action: ACS::ExecuteApi
Description: Ships logs to Simple Log Service.
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.",
"name-en": "ACS-OOS-ExampleExecuteECSDescribeRegions",
"categories": [
"ops"
]
},
"Parameters": {
"regionId": {
"Type": "String",
"AssociationProperty": "RegionId",
"Description": "The ID of the region"
},
"projectName": {
"Type": "String",
"Description": "The name of the project"
},
"logstoreName": {
"Type": "String",
"Description": "The name of the Logstore"
},
"Contents": {
"Type": "String",
"Description": "The content of the logs",
"AssociationProperty": "Json",
"Default": [
{
"log1": "value1"
},
{
"log2": "value2"
}
]
},
"Tags": {
"Type": "String",
"Description": "The tags that are added to the logs",
"AssociationProperty": "Json",
"Default": []
}
},
"Tasks": [
{
"Name": "SlsPutLogs",
"Action": "ACS::ExecuteApi",
"Description": "Ships logs to Simple Log Service",
"Properties": {
"Service": "log",
"API": "PutLogs",
"URI": "/logstores/{{ logstoreName }}/shards/lb",
"Method": "POST",
"Parameters": {
"RegionId": "{{ regionId }}",
"projectName": "{{ projectName }}",
"Logs": {
"Contents": "{{ Contents }}"
},
"Tags": "{{ Tags }}"
}
}
}
]
}Annexe : Paramètres de pagination automatique
Pour les OpenAPI prenant en charge la pagination, OOS permet la pagination automatique. Configurez la pagination automatique en spécifiant
AutoPaging. La pagination automatique est activée par défaut.Spécifiez le nombre d'entrées par page.
Si l'opération prend en charge à la fois (NextToken, MaxResults) et (PageNumber, PageSize), nous vous recommandons d'utiliser (NextToken, MaxResults).
Modèle d'exemple : Paramètres de pagination pour ECS DescribeInstances
FormatVersion: OOS-2019-06-01
Description: Runs one operation
Tasks:
- Name: ExecuteApi
Action: ACS::ExecuteApi
Description:
en: Perform a single ExecuteApi operation.
zh-cn: the description in Chinese
Properties:
Service: ecs
API: DescribeInstances
Parameters:
RegionId: cn-hangzhou
MaxResults: 50 # The maximum number of entries per page{
"FormatVersion": "OOS-2019-06-01",
"Description": "Runs one operation",
"Tasks": [
{
"Name": "ExecuteApi",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Perform a single ExecuteApi operation.",
"zh-cn": "the description in Chinese"
},
"Properties": {
"Service": "ecs",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "cn-hangzhou",
"MaxResults": 50
}
}
}
]
}