使用 OpenAPI 設定具有私有整合的 API - Amazon API Gateway

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 OpenAPI 設定具有私有整合的 API

您可以匯入 API OpenAPI 檔案來設定具有私有整合的 API。這些設定類似具有 HTTP 整合之 API 的 OpenAPI 定義,但例外如下:

  • 您必須將 connectionType 明確地設定為 VPC_LINK

  • 您必須將 connectionId 明確地設定為 VpcLink 的 ID 或參考 VpcLink ID 的階段變數。

  • 私有整合中的 uri 參數指向 VPC 中的 HTTP/HTTPS 端點,但改為用來設定整合請求的 Host 標頭。

  • 具有 VPC 中 HTTPS 端點之私有整合中的 uri 參數用來針對 VPC 端點上所安裝憑證中的網域名稱來驗證所指出的網域名稱。

您可以使用階段變數來參考 VpcLink ID。或者,您可以將 ID 值直接指派給 connectionId

下列 JSON 格式化 OpenAPI 檔案會顯示 API 的範例,具有階段變數 (${stageVariables.vpcLinkId}) 所參考的 VPC 連結:

OpenAPI 2.0
{ "swagger": "2.0", "info": { "version": "2017-11-17T04:40:23Z", "title": "MyApiWithVpcLink" }, "host": "p3wocvip9a.execute-api.us-west-2.amazonaws.com", "basePath": "/test", "schemes": [ "https" ], "paths": { "/": { "get": { "produces": [ "application/json" ], "responses": { "200": { "description": "200 response", "schema": { "$ref": "#/definitions/Empty" } } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200" } }, "uri": "http://my-vpclink-test-nlb-1234567890abcdef.us-east-2.amazonaws.com", "passthroughBehavior": "when_no_match", "connectionType": "VPC_LINK", "connectionId": "${stageVariables.vpcLinkId}", "httpMethod": "GET", "type": "http_proxy" } } } }, "definitions": { "Empty": { "type": "object", "title": "Empty Schema" } } }