Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API Gateway HTTP API CORS

I am using the new API Gateway HTTP which during the configuration enables you to add CORS. So I have set the Access-Control-Allow-Origin Header with the setting *.

However when I make a request using Postman I do not see that header and this i causing my VueJS Axios request to fail.

I previously used a Lambda Proxy Integration and did the following in my Lambda

"headers": { 
            "Access-Control-Allow-Origin": "*" 
        }

However the new HTTP API just does not seem to implement CORS. Maybe I am missing something simple.

--EDITS--

So I have continue to find an answer and came across a blog post from the guys at Serverless who set the following

It’ll ensure following headers:

Access-Control-Allow-Origin: *
Access-Control-Allow-Headers:

Content-Type, X-Amz-Date, Authorization, X-Api-Key, X-Amz-Security-Token, X-Amz-User-Agent
Access-Control-Allow-Methods:

OPTIONS, and all the methods defined in your routes (GET, POST, etc.)

I have tried these and redeployed and still only get the standard headers

Thanks

like image 569
tjmgis Avatar asked Mar 24 '20 11:03

tjmgis


People also ask

How do I fix the CORS issue in API gateway?

Cross-Origin Resource Sharing (CORS) errors occur when a server doesn't return the HTTP headers required by the CORS standard. To resolve a CORS error from an API Gateway REST API or HTTP API, you must reconfigure the API to meet the CORS standard.

Does API gateway allow HTTP?

You can integrate an API method with an HTTP endpoint using the HTTP proxy integration or the HTTP custom integration. API Gateway supports the following endpoint ports: 80, 443 and 1024-65535. With proxy integration, setup is simple.


1 Answers

For anyone using HTTP API and the proxy route ANY /{proxy+}

You will need to explicitly define your route methods in order for CORS to work.

enter image description here

Wish this was more explicit in the AWS Docs for Configuring CORS for an HTTP API

Was on a 2 hour call with AWS Support and they looped in one of their senior HTTP API developers, who made this recommendation.

Hopefully this post can save some people some time and effort.

like image 163
TrieuNomad Avatar answered Sep 20 '22 14:09

TrieuNomad