全部產品
Search
文件中心

CloudOps Orchestration Service:ACS::ExecuteAPI

更新時間:Sep 30, 2024

用途

此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 }}"
        }
      }
    }
  ]
}