閱讀642 返回首頁    go 技術社區[雲棲]


輕鬆使用阿裏雲資源編排,方便你的API管理

11月初,阿裏雲ROS正式發布API 網關(API Gateway)資源,為雲計算用戶提供高性能、高可用的 API 托管服務,幫助用戶對外開放其部署在 ECS、容器服務等阿裏雲產品上的應用,提供完整的 API 發布、管理、維護生命周期管理。用戶隻需進行簡單的操作,即可快速、低成本、低風險地開放數據或服務。

用戶隻需要按照自己的需求,根據ROS的模板規範,定義自己的API管理模板,就可以輕輕鬆鬆實現API組的創建/更新,API的創建/更新,API的發布或者版本切換,以及API授權,簽名,流控等等的配置預更新。

以創建和發布一個新API到測試環境為例。首先用戶先根據ROS的模板規範定義自己的模板,模板中會包含下麵的幾個資源,具體的資源介紹詳見幫助文檔,
ALIYUN::ApiGateway::Group,
ALIYUN::ApiGateway::API,
ALIYUN::ApiGateway::Deployment

一個最簡單的模板定義如下:
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": "Create an API Gateway",
"Parameters": {
"CustomStage": {
"Type": "String",
"Description": "環境",
"AllowedValues": [
"TEST",
"PRE",
"RELEASE"
],
"Label": "環境",
"Default": "TEST"
}
},
"Resources": {
"Group": {
"Type": "ALIYUN::ApiGateway::Group",
"Properties": {
"GroupName": "my_api_group",
"Description": "my api group"
}
},
"Deployment": {
"Type": "ALIYUN::ApiGateway::Deployment",
"Properties": {
"Description": "liyi_test",
"StageName": {
"Ref": "CustomStage"
},
"ApiId": {
"Fn::GetAtt": [
"API",
"ApiId"
]
},
"GroupId": {
"Fn::GetAtt": [
"Group",
"GroupId"
]
}
}
},
"API": {
"Type": "ALIYUN::ApiGateway::Api",
"Properties": {
"RequestConfig": {
"RequestPath": "/my_resource",
"RequestProtocol": "HTTP,HTTPS",
"RequestHttpMethod": "GET",
"PostBodyDescription": "k:v",
"BodyFormat": "FORM"
},
"ResultSample": "my_test sample result",
"ServiceConfig": {
"ServiceAddress": "https://my_url_site",
"MockResult": "Nothing",
"ContentTypeValue": "application/x-www-form-urlencoded; charset=UTF-8",
"ServiceVpcEnable": "FALSE",
"ServiceTimeOut": 20000,
"ServiceProtocol": "HTTP",
"ServicePath": "/my_data",
"ServiceHttpMethod": "GET",
"ContentTypeCatagory": "DEFAULT",
"Mock": "FALSE"
},
"ApiName": "my_test_first_api",
"Visibility": "PRIVATE",
"AuthType": "APP",
"ResultType": "JSON",
"FailResultSample": "my_test faile sample result",
"GroupId": {
"Fn::GetAtt": [
"Group",
"GroupId"
]
}
}
}
},
"Outputs": {
"APIId": {
"Value": {
"Fn::GetAtt": [
"API",
"ApiId"
]
}
},
"GroupId": {
"Value": {
"Fn::GetAtt": [
"Group",
"GroupId"
]
}
}
}
}

然後在ROS的控製台(ros.console.aliyun.com)提交你的模板:
進入ROS的控製台如下圖所示,然後點擊“新建資源棧”按鈕。
2

接著會展示新的頁麵如下,需要在新的頁麵中選擇region,填入上麵提供的模板,然後點擊“下一步”。
3

緊接著會切換到這個頁麵,需要再屬於一些創建時的參數信息,資源棧的名稱,以及你需要在哪個環境發布API。參數設置好之後,點擊“創建”按鈕。
4

ROS 編排引擎就會根據模板和參數信息,創建API分組,API,並最終發布到測試環境。返回到資源棧管理頁麵,可以看到如下麵的信息,名為“my_api_v1”的資源棧創建成功。
5

點擊資源棧名,就可以查看資源棧的相關屬性。我們上麵的模板中定義了要輸出API分組的ID和API 的ID。
6

跳轉到API 網關的控製台,就可以看到我們通過模板所創建的API。
7

以上是通過ROS的控製台來創建,發布API。

ROS 當前支持的所有 API 網關的資源類型如下:
ALIYUN::ApiGateway::Group
https://help.aliyun.com/document_detail/61467.html?spm=5176.doc61480.6.650.0oTm2p
創建 API 分組
ALIYUN::ApiGateway::StageConfig::SignatureBinding
https://help.aliyun.com/document_detail/61483.html?spm=5176.doc61482.6.652.43jUI8
創建 API 分組中測試、預發、線上環境變量
ALIYUN::ApiGateway::Api
https://help.aliyun.com/document_detail/61459.html?spm=5176.doc28930.6.645.VIyhF4
創建 API
ALIYUN::ApiGateway::App
https://help.aliyun.com/document_detail/61468.html?spm=5176.doc61459.6.646.jep7UM
創建應用
ALIYUN::ApiGateway::Authorization
https://help.aliyun.com/document_detail/61478.html?spm=5176.doc61468.6.647.wFQfvi
給 API 授權應用的訪問權限
ALIYUN::ApiGateway::CustomDomain
https://help.aliyun.com/document_detail/61479.html?spm=5176.doc61478.6.648.O62moc
給 API 分組創建綁定自定義域名
ALIYUN::ApiGateway::Deployment
https://help.aliyun.com/document_detail/61480.html?spm=5176.doc61479.6.649.s0Ltp0
發布 API 或快速切換 API 版
ALIYUN::ApiGateway::Signature
https://help.aliyun.com/document_detail/61482.html?spm=5176.doc61467.6.651.JHTCZz
創建後端簽名密鑰
ALIYUN::ApiGateway::SignatureBinding
https://help.aliyun.com/document_detail/61483.html?spm=5176.doc61482.6.652.43jUI8
綁定 API 與後端簽名密鑰
ALIYUN::ApiGateway::TrafficControl
https://help.aliyun.com/document_detail/61485.html?spm=5176.doc61484.6.654.u6Ymvw
創建用戶自定義的流控策略
ALIYUN::ApiGateway::TrafficControlBinding
https://help.aliyun.com/document_detail/61488.html?spm=5176.doc61485.6.655.cz94Ob
給 API 綁定用戶自定義流控
ALIYUN::ApiGateway::VpcAccessConfig
https://help.aliyun.com/document_detail/61489.html?spm=5176.doc61488.6.656.KXYFQT
配置 VPC 授權以便專有網絡的 API 能對外提供服務

ROS也支持openAPI的方式做資源的操作,具體可以參考ROS雲棲博客索引
https://yq.aliyun.com/articles/57553?spm=5176.100239.0.0.LzywAe
中的這兩篇文章,
1、《阿裏雲資源編排服務Python SDK使用入門 》
https://yq.aliyun.com/articles/6904?spm=5176.100239.blogcont57553.66.N4yGwL
2、《阿裏雲資源編排服務Java SDK使用入門》
https://yq.aliyun.com/articles/113503?spm=5176.100239.blogcont57553.67.N4yGwL

同時用戶也可以通過ROS的命令行
https://yq.aliyun.com/articles/215216?spm=5176.100239.blogcont57553.72.N4yGwL
工具創建實現資源的創建,更新等等操作。

最後更新:2017-11-14 15:34:31

  上一篇:go  睿雲智合的持續交付的傳統的SOA的說法
  下一篇:go  阿裏雲CDN的雙11再進化