Set up an edge-optimized API by importing
OpenAPI definitions
You can set up an API in API Gateway by specifying OpenAPI definitions of appropriate
API Gateway API entities and importing the OpenAPI definitions into API Gateway.
The following OpenAPI definitions describe the simple API, exposing only the
GET /
method integrated with an HTTP endpoint of the PetStore
website in the backend, and returning a 200 OK
response.
- 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"
}
}
}
}
}
The following procedure describes how to import these OpenAPI definitions into
API Gateway using the API Gateway console.
- Old REST API console
-
We've redesigned the API Gateway console. The old console experience will no longer be available starting December 2023.
To import the simple OpenAPI definitions using the API Gateway console
-
Sign in to the API Gateway console.
-
Choose Create API.
-
Choose Import from OpenAPI.
-
If you saved the preceding OpenAPI definitions in a file, choose
Select OpenAPI File. You can also copy the OpenAPI
definitions and paste them into the import text editor.
-
Choose Import to finish importing the OpenAPI
definitions.
- New REST API console
To import the simple OpenAPI definitions using the API Gateway console
-
Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway.
-
Choose Create API, and then for REST API, choose Import.
-
If you saved the preceding OpenAPI definitions in a file, choose
Choose file. You can also copy the OpenAPI
definitions and paste them into the import text editor.
For API endpoint type, select Edge-optimized.
-
Choose Create API to import the OpenAPI
definitions.
To import the OpenAPI definitions using the AWS CLI, save the OpenAPI definitions
into a file and then run the following command, assuming that you use the
us-west-2
region and the absolute OpenAPI file path is
file:///path/to/API_OpenAPI_template.json
:
aws apigateway import-rest-api --body 'file:///path/to/API_OpenAPI_template.json' --region us-west-2