Skip to content

Latest commit

 

History

History
195 lines (103 loc) · 8.53 KB

rest-api-gateway.md

File metadata and controls

195 lines (103 loc) · 8.53 KB

Set up REST API Gateway

WARNING: you are on the master branch, please refer to the docs on the branch that matches your cortex version

When api_gateway: public is set in your API's networking configuration (which is the default setting), Cortex will create an "HTTP" API Gateway in AWS for your API (see the networking docs for more information).

However, there may be situations where you need to use AWS's "REST" API Gateway, e.g. to enforce IAM-based auth. Until #1197 is resolved, a REST API Gateway can be used by following these steps.

If your API load balancer is internet-facing (which is the default, or you explicitly 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.

If your API load balancer is internet-facing

Step 1

Disable the default API Gateway:

Step 2

Go to the API Gateway console, select "REST API" under "Choose an API type", and click "Build"

step 1

Step 3

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"

step 2

Step 4

Select "Actions" > "Create Resource"

step 3

Step 5

Select "Configure as proxy resource" and "Enable API Gateway CORS", and click "Create Resource"

step 4

Step 6

Select "HTTP Proxy" and set "Endpoint URL" to "http://<BASE_API_ENDPOINT>/{proxy}". You can get your base API 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".

step 5

Step 7

Select "Actions" > "Deploy API"

step 6

Step 8

Create a new stage (e.g. "dev") and click "Deploy"

step 7

Step 9

Copy your "Invoke URL"

step 8

Using your new endpoint

You may now use the "Invoke URL" in place of your APIs endpoint in your client. For example, this curl request:

curl http://a9eaf69fd125947abb1065f62de59047-81cdebc0275f7d96.elb.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json

Would become:

curl https://31qjv48rs6.execute-api.us-west-2.amazonaws.com/dev/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json

Cleanup

Delete the API Gateway before spinning down your Cortex cluster:

delete api gateway

If your API load balancer is internal

Step 1

Disable the default API Gateway:

Step 2

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:

step 1

Take note of the load balancer's name.

Step 3

Go to the API Gateway console, click "VPC Links" on the left sidebar, and click "Create"

step 2

Step 4

Select "VPC link for REST APIs", name your VPC link (e.g. "cortex"), select the API load balancer (identified in Step 1), and click "Create"

step 3

Step 5

Wait for the VPC link to be created (it will take a few minutes)

step 4

Step 6

Go to the API Gateway console, select "REST API" under "Choose an API type", and click "Build"

step 5

Step 7

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"

step 6

Step 8

Select "Actions" > "Create Resource"

step 7

Step 9

Select "Configure as proxy resource" and "Enable API Gateway CORS", and click "Create Resource"

step 8

Step 10

Select "VPC Link", select "Use Proxy Integration", choose your newly-created VPC Link, and set "Endpoint URL" to "http://<BASE_API_ENDPOINT>/{proxy}". You can get your base API 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"

step 9

Step 11

Select "Actions" > "Deploy API"

step 10

Step 12

Create a new stage (e.g. "dev") and click "Deploy"

step 11

Step 13

Copy your "Invoke URL"

step 12

Using your new endpoint

You may now use the "Invoke URL" in place of your APIs endpoint in your client. For example, this curl request:

curl http://a5044e34a352d44b0945adcd455c7fa3-32fa161d3e5bcbf9.elb.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json

Would become:

curl https://lrivodooqh.execute-api.us-west-2.amazonaws.com/dev/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json

Cleanup

Delete the API Gateway and VPC Link before spinning down your Cortex cluster:

delete api

delete vpc link