By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How do I deactivate the API Gateway default endpoint for REST or HTTP APIs?

3 minute read
0

I want to allow clients to invoke my APIs with only the custom domain name.

Short description

Amazon API Gateway REST APIs and HTTP APIs use a default API endpoint in the following format: https://API_ID.execute-api.REGION.amazonaws.com. If you use a custom domain name for your API Gateway REST or HTTP APIs, then you can deactivate the default endpoint. This allows all traffic to route to your APIs through the custom domain name.

Resolution

To deactivate the default endpoint, use the API Gateway console, AWS Command Line Interface (AWS CLI), or AWS CloudFormation. After you deactivate the default endpoint, you must initiate a deployment for the update to take effect.

Note: If you receive errors when running AWS CLI commands, make sure that you're using the most recent version of the AWS CLI.

API Gateway console

REST API

  1. Open the API Gateway console.
  2. In the navigation pane, choose APIs, and then choose your REST API.
  3. In the navigation pane, choose Settings.
  4. For the Default Endpoint, choose Disabled, and then choose Save Changes.
  5. In the navigation pane, choose Resources, Actions, and then choose Deploy API.

HTTP API

  1. Open the API Gateway console.
  2. In the navigation pane, choose APIs, and then choose your HTTP API.
  3. In the navigation pane, choose API: API_NAME(API_ID).
  4. Choose Edit.
  5. For the Default Endpoint, choose Disabled, and then choose Save.

AWS CLI

REST API
Run the AWS CLI command update-rest-api:

aws apigateway update-rest-api --rest-api-id abcdef123 --patch-operations op=replace,path=/disableExecuteApiEndpoint,value='True'

To deploy the updated API, run the AWS CLI command create-deployment:

aws apigateway create-deployment --rest-api-id abcdef123 --stage-name dev

Note: Replace api-id abcdef123 and stage_name dev with your REST API ID and respective stage.

HTTP API

Run the AWS CLI command update-api:

aws apigatewayv2 update-api --api-id abcdef123 --disable-execute-api-endpoint

To deploy the updated API, run the AWS CLI command create-deployment:

aws apigatewayv2 create-deployment --api-id abcdef123 --stage-name dev

Note: Replace api_id abcdef123 and stage_name dev with your HTTP API ID and respective stage.

CloudFormation template

To deactivate the default endpoint from a CloudFormation template, set the DisableExecuteApiEndpoint parameter to True. Update the CloudFormation template for a REST API or HTTP API.

Important: If you invoke the API with the default endpoint URL, then deactivating the default endpoint results in an error. You receive an HTTP 403 Forbidden error for REST APIs or an HTTP 404 Not Found error for HTTP APIs.

Related information

Invoking a REST API in Amazon API Gateway

How do I troubleshoot HTTP 403 errors from API Gateway?

AWS OFFICIAL
AWS OFFICIALUpdated 2 years ago