説明
ACS::ExecuteAPI アクションを使用すると、Elastic Compute Service (ECS) などのクラウドサービスの API 操作を呼び出すことができます。API 操作が非同期で呼び出された場合は、ACS::WaitFor アクションを使用して、指定したリソースが期待される状態になるまで待機できます。
構文
説明
Tasks.Properties.API 属性は呼び出す API 操作を指定するため、Tasks.Properties.Parameters 属性で API 操作を再度指定する必要はありません。
RPC API 操作
Tasks:
- Name: executeAPITaskExample
Action: ACS::ExecuteAPI
Properties:
Service: ECS # 必須。Resource Access Management (RAM) 内のクラウドサービスの Alibaba Cloud Resource Name (ARN)。名前は大文字と小文字を区別しません (例: ECS、RDS、FC)。
API: DescribeInstances # 必須。クラウドサービスの API 操作の名前。名前は大文字と小文字を区別しません (例: DescribeInstances)。
AutoPaging: false # オプション。異なるページに結果を返す API 操作について、すべての結果を取得するために自動的にページをめくるかどうかを指定します。デフォルト値: true。
Parameters: # API 操作の呼び出しに必要なパラメーター。詳細については、関連ドキュメントをご参照ください。
Parameter1: Value1
Parameter2: Value2
Outputs:
OutputParameter1:
ValueSelector: 'jq selector' # 返すデータを選択するための jQuery セレクター。jQuery セレクターは、API 操作によって返された JSON データから情報を抽出します。jQuery 構文の詳細については、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 # 必須。RAM 内のクラウドサービスの ARN。名前は大文字と小文字を区別しません (例: OSS、ECS、RDS、FC)。
API: PutBucket # 必須。クラウドサービスの API 操作の名前。名前は大文字と小文字を区別しません (例: PutBucket)。
Method: PUT # 必須。API 操作の HTTP リクエストメソッド。
URI: '' # API 操作で使用される Uniform Resource Identifier (URI)。
Headers: # オプション。API 操作のリクエストヘッダー。この属性は次の形式で指定します。
requestHeader1: 'requestHeader1Value'
Parameters: # オプション。API 操作の共通パラメーター。
commonParameter1: 'commonParameter1Value'
commonParameter2: 'commonParameter2Value'
# オプション。API 操作のリクエスト本文。この属性は 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 操作を呼び出す
FormatVersion: OOS-2019-06-01
Description: インスタンスステータスを指定して ECS インスタンスを表示します。
Parameters:
status:
Description: クエリインスタンスの ECS インスタンスステータス。
Type: String
Tasks:
- Name: describeInstances
Action: ACS::ExecuteAPI
Description: インスタンスステータスを指定して ECS インスタンスを表示します。
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": "インスタンスステータスを指定して ECS インスタンスを表示します。",
"Parameters": {
"status": {
"Description": "クエリインスタンスの ECS インスタンスステータス。",
"Type": "String"
}
},
"Tasks": [
{
"Name": "describeInstances",
"Action": "ACS::ExecuteAPI",
"Description": "インスタンスステータスを指定して ECS インスタンスを表示します。",
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"Status": "{{ status }}"
}
},
"Outputs": {
"instanceIds": {
"Type": "List",
"ValueSelector": "Instances.Instance[].InstanceId"
}
}
}
],
"Outputs": {
"instanceIds": {
"Type": "List",
"Value": "{{ describeInstances.instanceIds }}"
}
}
}ROA スタイルで Object Storage Service (OSS) の PutBucket 操作を呼び出す
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": "."
}
}
}
]
}ROA スタイルで Simple Log Service の PutLogs 操作を呼び出す
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": "ログを 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 }}"
}
}
}
]
}付録: 自動ページング設定
ページングをサポートする OpenAPI の場合、OOS は自動ページングをサポートしています。
AutoPagingを指定することで、自動ページングを設定できます。デフォルトでは、自動ページングがサポートされています。1 ページあたりのエントリ数を指定できます。
操作で (NextToken, MaxResults) と (PageNumber, PageSize) の両方がサポートされている場合は、(NextToken, MaxResults) を指定することをお勧めします。
サンプルテンプレート: ECS DescribeInstances のページング設定
FormatVersion: OOS-2019-06-01
Description: 1 つの操作を実行します
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 # 1 ページあたりの最大エントリ数{
"FormatVersion": "OOS-2019-06-01",
"Description": "1 つの操作を実行します",
"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
}
}
}
]
}