Configuring CORS for an HTTP API - Amazon API Gateway

Configuring CORS for an HTTP API

Cross-origin resource sharing (CORS) is a browser security feature that restricts HTTP requests that are initiated from scripts running in the browser. If you cannot access your API and receive an error message that contains Cross-Origin Request Blocked, you might need to enable CORS.

CORS is typically required to build web applications that access APIs hosted on a different domain or origin. You can enable CORS to allow requests to your API from a web application hosted on a different domain. For example, if your API is hosted on https://{api_id}.execute-api.{region} and you want to call your API from a web application hosted on, your API must support CORS.

If you configure CORS for an API, API Gateway automatically sends a response to preflight OPTIONS requests, even if there isn't an OPTIONS route configured for your API. For a CORS request, API Gateway adds the configured CORS headers to the response from an integration.


If you configure CORS for an API, API Gateway ignores CORS headers returned from your backend integration.

You can specify the following parameters in a CORS configuration. To add these parameters using the API Gateway HTTP API console, choose Add after you enter your value.

CORS headers CORS configuration property Example values




  • * (allow all origins)

  • https://* (allow any origin that begins with https://)

  • http://* (allow any origin that begins with http://)






Date, x-api-id









Authorization, *

To return CORS headers, your request must contain an origin header.

Your CORS configuration might look similar to the following:

      CORS configuration for HTTP APIs

Configuring CORS for an HTTP API with a $default route and JWT authorizer

You can enable CORS and configure authorization for any route of an HTTP API. When you enable CORS and authorization for the $default route, there are some special considerations. The $default route catches requests for all methods and routes that you haven't explicitly defined, including OPTIONS requests. To support unauthorized OPTIONS requests, add an OPTIONS /{proxy+} route to your API that doesn't require authorization and attach an integration to the route. The OPTIONS /{proxy+} route has higher priority than the $default route. As a result, it enables clients to submit OPTIONS requests to your API without authorization. For more information about routing priorities, see Routing API requests.

Configure CORS for an HTTP API by using the AWS CLI

You can use the following command to enable CORS requests from

aws apigatewayv2 update-api --api-id api-id --cors-configuration AllowOrigins=""

For more information, see CORS in the Amazon API Gateway Version 2 API Reference.