使用 OpenAPI 设置具有私有集成的 API - Amazon API Gateway
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 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 具有 VPC 链接,通过阶段变量 (${stageVariables.vpcLinkId}) 来引用:

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