通过导入 OpenAPI 定义设置边缘优化的 API - Amazon API Gateway
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

通过导入 OpenAPI 定义设置边缘优化的 API

通过指定相应 API Gateway API 实体的 OpenAPI 定义并将 OpenAPI 定义导入 API Gateway,您可以在 API Gateway 中设置 API。

以下 OpenAPI 定义描述了简单 API,仅在后端公开了与 PetStore网站 HTTP 端点集成的GET /方法,并返回了响应。200 OK

OpenAPI 2.0
{ "swagger": "2.0", "info": { "title": "Simple PetStore (OpenAPI)" }, "schemes": [ "https" ], "paths": { "/pets": { "get": { "responses": { "200": { "description": "200 response" } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200" } }, "uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets", "passthroughBehavior": "when_no_match", "httpMethod": "GET", "type": "http" } } }, "/pets/{petId}": { "get": { "parameters": [ { "name": "petId", "in": "path", "required": true, "type": "string" } ], "responses": { "200": { "description": "200 response" } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200" } }, "requestParameters": { "integration.request.path.id": "method.request.path.petId" }, "uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets/{id}", "passthroughBehavior": "when_no_match", "httpMethod": "GET", "type": "http" } } } } }

以下过程介绍如何使用 API Gateway 控制台将这些 OpenAPI 定义导入到 API Gateway 中。

使用 API Gateway 控制台导入简单的 OpenAPI 定义
  1. 通过以下网址登录到 API Gateway 控制台:https://console.aws.amazon.com/apigateway

  2. 选择创建 API,然后为 REST API 选择构建

  3. 如果您已将上述 OpenAPI 定义保存在文件中,请选择选择文件。此外,您还可以复制 OpenAPI 定义并将其粘贴到导入文本编辑器中。

  4. 对于 API 端点类型,选择边缘优化

  5. 选择创建 API 以导入 OpenAPI 定义。

要使用导入 OpenAPI 定义 Amazon CLI,请将 OpenAPI 定义保存到文件中,然后运行以下命令,假设您使用的是该us-west-2区域并且绝对的 OpenAPI 文件路径为:file:///path/to/API_OpenAPI_template.json

aws apigateway import-rest-api --body 'file:///path/to/API_OpenAPI_template.json' --region us-west-2