A Terraform module to add an OPTIONS method to allow Cross-Origin Resource Sharing (CORS) preflight requests.
module "cors" {
source = "github.com/squidfunk/terraform-aws-api-gateway-enable-cors"
version = "0.3.0"
api_id = "<api_id>"
api_resource_id = "<api_resource_id>"
}
By default, this will create a new MOCK
endpoint on the provided API Gateway
resource allowing CORS preflight requests for all methods and
all origins by default. Of course this can be customized using variables
as stated in the next section.
The following variables can be configured:
- Description: API identifier
- Default:
none
- Description: API resource identifier
- Default:
none
-
Description: Allow headers (
Access-Control-Allow-Headers
) -
Default:
[ "Authorization", "Content-Type", "X-Amz-Date", "X-Amz-Security-Token", "X-Api-Key" ]
-
Description: Allow methods (
Access-Control-Allow-Methods
) -
Default:
[ "OPTIONS", "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE" ]
- Description: Allow origin (
Access-Control-Allow-Origin
) - Default:
"*"
- Description: Allow caching time (
Access-Control-Allow-Max-Age
) - Default:
"7200"
- Description: Allow credentials (
Access-Control-Allow-Credentials
) - Default:
none
None.
MIT License
Copyright (c) 2018-2019 Martin Donath
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.