简体   繁体   中英

Unable to set Access-Allow-Control-Origin in AWS api-gateway for CORS - returns invalid format error

I am having trouble with setting up CORS on AWS API-Gateway.

To provide a bit of background, CORS on API_gateway supports 6 fields as below.

Access-Allow-Control-Origin - supports 'https://www.example.com' , '*' , 'https://*' , and 'http://*'

I got this from https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html

When I try '*' and 'https://www.domain-name.com' , I get the following errors:

在此处输入图片说明

I am not sure what format to follow. Also, the '*' seems to be referenced in various links.

Any help greatly appreciated.

If you have enabled cors on your api gateway, the next place to look is the application code such as lambda.

Make sure the Lambda is returning the correct cross origin headers in both successful and failure scenarios. please check if your code is returning cross origin headers all the time.

To troubleshoot,

Method 1: Check if the request is reaching the lambda from the cloud watch logs. You can find some useful information such as exceptions thrown by the code.

Method 2: Point the Api gateway target to the Mock integration type. If the mock integration works, then the problem is the application code. otherwise the problem is in your api gateway end point.

Also note that any headers you use should be white listed in the Access-Control-Allow-headers section when you enable to cors for your method/resource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM