-
Notifications
You must be signed in to change notification settings - Fork 607
Add REST API Gateway guide #1505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c8b9ed
Add REST API Gateway guide
deliahu 6fb3e42
Update rest-api-gateway.md
deliahu 4bb2fce
Update rest-api-gateway.md
deliahu 399842d
Merge branch 'master' into rest-api-gateway-guide
RobertLucian 16d80c1
Merge branch 'master' into rest-api-gateway-guide
vishalbollu 5c684b8
Merge branch 'master' into rest-api-gateway-guide
vishalbollu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
# 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](../deployments/networking.md) 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](https://github.com/cortexlabs/cortex/issues/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](#if-your-api-load-balancer-is-internet-facing) 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](#if-your-api-load-balancer-is-internal) of this guide. | ||
|
||
## If your API load balancer is internet-facing | ||
|
||
### Step 1 | ||
|
||
Disable the default API Gateway: | ||
|
||
* If you haven't created your cluster yet, you can set `api_gateway: none` in your [cluster configuration file](../cluster-management/config.md) before creating your cluster. | ||
* If you have already created your cluster, you can set `api_gateway: none` in the `networking` field of your [Realtime API configuration](../deployments/realtime-api/api-configuration.md) and/or [Batch API configuration](../deployments/batch-api/api-configuration.md), and then re-deploy your API. | ||
|
||
### Step 2 | ||
|
||
Go to the [API Gateway console](https://console.aws.amazon.com/apigateway/home), select "REST API" under "Choose an API type", and click "Build" | ||
|
||
 | ||
|
||
### 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 4 | ||
|
||
Select "Actions" > "Create Resource" | ||
|
||
 | ||
|
||
### Step 5 | ||
|
||
Select "Configure as proxy resource" and "Enable API Gateway CORS", and click "Create Resource" | ||
|
||
 | ||
|
||
### 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 7 | ||
|
||
Select "Actions" > "Deploy API" | ||
|
||
 | ||
|
||
### Step 8 | ||
|
||
Create a new stage (e.g. "dev") and click "Deploy" | ||
|
||
 | ||
|
||
### Step 9 | ||
|
||
Copy your "Invoke URL" | ||
|
||
 | ||
|
||
### 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: | ||
|
||
```bash | ||
curl http://a9eaf69fd125947abb1065f62de59047-81cdebc0275f7d96.elb.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json | ||
``` | ||
|
||
Would become: | ||
|
||
```bash | ||
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: | ||
|
||
 | ||
|
||
## If your API load balancer is internal | ||
|
||
### Step 1 | ||
|
||
Disable the default API Gateway: | ||
|
||
* If you haven't created your cluster yet, you can set `api_gateway: none` in your [cluster configuration file](../cluster-management/config.md) before creating your cluster. | ||
* If you have already created your cluster, you can set `api_gateway: none` in the `networking` field of your [Realtime API configuration](../deployments/realtime-api/api-configuration.md) and/or [Batch API configuration](../deployments/batch-api/api-configuration.md), and then re-deploy your API. | ||
|
||
### 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: | ||
|
||
 | ||
|
||
Take note of the load balancer's name. | ||
|
||
### Step 3 | ||
|
||
Go to the [API Gateway console](https://console.aws.amazon.com/apigateway/home), click "VPC Links" on the left sidebar, and click "Create" | ||
|
||
 | ||
|
||
### 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 5 | ||
|
||
Wait for the VPC link to be created (it will take a few minutes) | ||
|
||
 | ||
|
||
### Step 6 | ||
|
||
Go to the [API Gateway console](https://console.aws.amazon.com/apigateway/home), select "REST API" under "Choose an API type", and click "Build" | ||
|
||
 | ||
|
||
### 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 8 | ||
|
||
Select "Actions" > "Create Resource" | ||
|
||
 | ||
|
||
### Step 9 | ||
|
||
Select "Configure as proxy resource" and "Enable API Gateway CORS", and click "Create Resource" | ||
|
||
 | ||
|
||
### 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 11 | ||
|
||
Select "Actions" > "Deploy API" | ||
|
||
 | ||
|
||
### Step 12 | ||
|
||
Create a new stage (e.g. "dev") and click "Deploy" | ||
|
||
 | ||
|
||
### Step 13 | ||
|
||
Copy your "Invoke URL" | ||
|
||
 | ||
|
||
### 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: | ||
|
||
```bash | ||
curl http://a5044e34a352d44b0945adcd455c7fa3-32fa161d3e5bcbf9.elb.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json | ||
``` | ||
|
||
Would become: | ||
|
||
```bash | ||
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: | ||
|
||
 | ||
|
||
 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.