HTTPS with API Gateway
This guide shows how set up AWS API Gateway for your Cortex APIs, which is the simplest way to enable HTTPS if a custom domain is not required. See here for how to set up a custom domain with SSL certificates instead.
Please note that one limitation of API Gateway is that there is a 30-second time limit for all requests.
If your API load balancer is internet-facing (which is the default, or you set api_load_balancer_scheme: internet-facing
in your cluster configuration file before creating your cluster), use the first section of this guide.
If your API load balancer is internal (i.e. you set api_load_balancer_scheme: internal
in your cluster configuration file before creating your cluster), use the second section of this guide.
Internet-facing load balancer
This section applies if your API load balancer is internet-facing (which is the default, or you set api_load_balancer_scheme: internet-facing
in your cluster configuration file before creating your cluster). If your API load balancer is internal, see the internal load balancer section below.
There are two types of API Gateways that can be used when your load balancer is internet-facing: HTTP and REST. HTTP APIs are faster and less expensive, while REST APIs have more features an allow for more control. See the following section for creating an HTTP API, or skip to the next section for creating a REST API.
HTTP API
Create an API Gateway
Go to the API Gateway console, select "HTTP API" under "Choose an API type", and click "Build".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668597-35ad8d8e-8b5f-4274-bbb3-62ff47e5d544.png&width=768&dpr=4&quality=100&sign=ef659c92&sv=1)
Click "Add integration".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668635-f92df672-f516-45e0-a152-538aff901c0d.png&width=768&dpr=4&quality=100&sign=bd900d5d&sv=1)
Click the drop-down menu, and select "HTTP".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668655-78754a51-c77a-4a03-a548-78ab991d1486.png&width=768&dpr=4&quality=100&sign=32a78226&sv=1)
Set the "URL endpoint" to http://API_LOAD_BALANCER_ENDPOINT/{proxy}
. You can get your API load balancer endpoint via cortex cluster info
; make sure to prepend http://
and append /{proxy}
. For example, mine is: http://aa9f5fdabfa6446aca53a526f59bc3c5-18cd00a628421fa3.elb.us-east-1.amazonaws.com/{proxy}
.
Choose a name for your API (e.g. "cortex"), and click "Next".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668735-b57976c7-f68e-4a28-ab2a-92cfad5b49bb.png&width=768&dpr=4&quality=100&sign=fe73aa5e&sv=1)
On the next page, update the pre-populated route's resource path to /{proxy+}
, and click "Next".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668752-21aef8dd-1e75-41a5-bfc5-1e7157efbe01.png&width=768&dpr=4&quality=100&sign=3fbb03cf&sv=1)
Click "Next" again.
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668761-8a177f6e-1977-48a2-be84-4b0df0105283.png&width=768&dpr=4&quality=100&sign=6f3e6c66&sv=1)
Click "Create".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668770-69fd3fbe-24e4-4a8a-8413-d50c779392c5.png&width=768&dpr=4&quality=100&sign=728f2e3&sv=1)
Copy your "Invoke URL" for the $default
stage
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668795-b18b564c-7091-432c-a4fd-a5a8bb157946.png&width=768&dpr=4&quality=100&sign=5095d12b&sv=1)
Use your new endpoint
You may now use the "Invoke URL" in place of your API load balancer endpoint in your client. For example, this curl request:
Would become:
Cleanup
Delete the API Gateway before spinning down your Cortex cluster:
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F125668816-83bce6bf-cf0e-4835-8d18-d641eb6cdb29.png&width=768&dpr=4&quality=100&sign=fceb633f&sv=1)
REST API
Create an API Gateway
Go to the API Gateway console, select "REST API" under "Choose an API type", and click "Build".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F78293216-18269e80-74dd-11ea-9e68-86922c2cbc7c.png&width=768&dpr=4&quality=100&sign=a68b1bb2&sv=1)
Select "REST" and "New API", name your API (e.g. "cortex"), select either "Regional" or "Edge optimized" (depending on your preference), and click "Create API".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F78293434-66d43880-74dd-11ea-92d6-692158171a3f.png&width=768&dpr=4&quality=100&sign=b91c0853&sv=1)
Select "Actions" > "Create Resource":
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80154502-8b6b7f80-8574-11ea-9c78-7d9f277bf55b.png&width=768&dpr=4&quality=100&sign=5eaa7b3d&sv=1)
Select "Configure as proxy resource" and "Enable API Gateway CORS", and click "Create Resource"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80154565-ad650200-8574-11ea-8753-808cd35902e2.png&width=768&dpr=4&quality=100&sign=fe6d905a&sv=1)
Select "HTTP Proxy" and set "Endpoint URL" to http://API_LOAD_BALANCER_ENDPOINT/{proxy}
. You can get your API load balancer endpoint via cortex cluster info
; make sure to prepend http://
and append /{proxy}
. For example, mine is: http://a9eaf69fd125947abb1065f62de59047-81cdebc0275f7d96.elb.us-west-2.amazonaws.com/{proxy}
.
Leave "Content Handling" set to "Passthrough" and Click "Save".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80154735-13ea2000-8575-11ea-83ca-58f182df83c6.png&width=768&dpr=4&quality=100&sign=df2fda5d&sv=1)
Select "Actions" > "Deploy API"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80154802-2c5a3a80-8575-11ea-9ab3-de89885fd658.png&width=768&dpr=4&quality=100&sign=a5dcc559&sv=1)
Create a new stage (e.g. "dev") and click "Deploy"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80154859-4431be80-8575-11ea-9305-50384b1f9847.png&width=768&dpr=4&quality=100&sign=856c79b2&sv=1)
Copy your "Invoke URL"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80154911-5dd30600-8575-11ea-9682-1a7328783011.png&width=768&dpr=4&quality=100&sign=71a98307&sv=1)
Use your new endpoint
You may now use the "Invoke URL" in place of your API load balancer endpoint in your client. For example, this curl request:
Would become:
Cleanup
Delete the API Gateway before spinning down your Cortex cluster:
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80155073-bdc9ac80-8575-11ea-99a1-95c0579da79e.png&width=768&dpr=4&quality=100&sign=d34ae9c2&sv=1)
Internal load balancer
This section applies if your API load balancer is internal (i.e. you set api_load_balancer_scheme: internal
in your cluster configuration file before creating your cluster). If your API load balancer is internet-facing, see the internet-facing load balancer section above.
Create a VPC Link
Navigate to AWS's EC2 Load Balancer dashboard and locate the Cortex API load balancer. You can determine which is the API load balancer by inspecting the kubernetes.io/service-name
tag:
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80142777-961c1980-8560-11ea-9202-40964dbff5e9.png&width=768&dpr=4&quality=100&sign=78ddb1a3&sv=1)
Take note of the load balancer's name.
Go to the API Gateway console, click "VPC Links" on the left sidebar, and click "Create"
Select "VPC link for REST APIs", name your VPC link (e.g. "cortex"), select the API load balancer, and click "Create".
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80143027-03c84580-8561-11ea-92de-9ed0a5dfa593.png&width=768&dpr=4&quality=100&sign=e35730b0&sv=1)
Wait for the VPC link to be created (it will take a few minutes)
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80144088-bbaa2280-8562-11ea-901b-8520eb253df7.png&width=768&dpr=4&quality=100&sign=6a44a1b7&sv=1)
Create an API Gateway
Go to the API Gateway console, select "REST API" under "Choose an API type", and click "Build"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F78293216-18269e80-74dd-11ea-9e68-86922c2cbc7c.png&width=768&dpr=4&quality=100&sign=a68b1bb2&sv=1)
Select "REST" and "New API", name your API (e.g. "cortex"), select either "Regional" or "Edge optimized" (depending on your preference), and click "Create API"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F78293434-66d43880-74dd-11ea-92d6-692158171a3f.png&width=768&dpr=4&quality=100&sign=b91c0853&sv=1)
Select "Actions" > "Create Resource"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80141938-3cffb600-855f-11ea-9c1c-132ca4503b7a.png&width=768&dpr=4&quality=100&sign=be1bf91c&sv=1)
Select "Configure as proxy resource" and "Enable API Gateway CORS", and click "Create Resource"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80142124-80f2bb00-855f-11ea-8e4e-9413146e0815.png&width=768&dpr=4&quality=100&sign=1f4228af&sv=1)
Select "VPC Link", select "Use Proxy Integration", choose your newly-created VPC Link, and set "Endpoint URL" to http://API_LOAD_BALANCER_ENDPOINT/{proxy}
. You can get your API load balancer endpoint via cortex cluster info
; make sure to prepend http://
and append /{proxy}
. For example, mine is: http://a5044e34a352d44b0945adcd455c7fa3-32fa161d3e5bcbf9.elb.us-west-2.amazonaws.com/{proxy}
. Click "Save"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80147407-4f322200-8568-11ea-8ef5-df5164c1375f.png&width=768&dpr=4&quality=100&sign=fb9efb94&sv=1)
Select "Actions" > "Deploy API"
![](https://docs.cortexlabs.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F808475%2F80147555-86083800-8568-11ea-86af-1b1e38c9d322.png&width=768&dpr=4&quality=100&sign=c2f472ed&sv=1)
Create a new stage (e.g. "dev") and click "Deploy"
Copy your "Invoke URL"
Use your new endpoint
You may now use the "Invoke URL" in place of your API load balancer endpoint in your client. For example, this curl request:
Would become:
Cleanup
Delete the API Gateway and VPC Link before spinning down your Cortex cluster:
Last updated