Gash
Gash

Reputation: 11

AWS API Gateway HTTP APIs CORS issue when use ANY method

I have trouble when use ANY method in API Gateway HTTP APIs routes setting but after I changed HTTP Method to PATCH it's working fine.

Why is that? Isn't ANY method should work with all HTTP Verbs?

Upvotes: 0

Views: 572

Answers (2)

vaquar khan
vaquar khan

Reputation: 11479

You need to enable CORS

Go to API Gateway -> Select your API endpoint -> Select the method ->click dropdown ACTIONS > Enable CORS

Redeploy API

enter image description here

Upvotes: 0

Matt Timmermans
Matt Timmermans

Reputation: 59358

The browser will check the CORS headers at your URL by sending an OPTIONS request.

If your route doesn't support the OPTIONS method, then API Gateway will implement it for you.

If your route says ANY method, then you have to implement OPTIONS yourself. You probably just haven't implemented this properly. Note that it can be quite difficult, because that OPTIONS request will not be sent with any authentication headers, etc., so you can't use the built-in authorizers.

Usually it's best just to make explicit routes for the methods you support and let AWS handle OPTIONS.

Upvotes: 1

Related Questions