Trying to enable CORS

0

I have:

  • A lambda function
  • API gateway pointing to it
  • This API gateway has a custom domain subdomain.mydomain.com, which is associated with <domain>.cloudfront.net

When I access the API gateway directly with its API id (<string>.execute-api.us-east-2.amazonaws.com/latest) CORS works as expected (I will get the access-control-allow-origin: * header).

However, if I access the API gateway with the custom domain (subdomain.mydomain.com), I will not get that header and CORS will not work. Instead I get some CloudFront errors:

x-amzn-errortype: ForbiddenException
x-cache: Error from cloudfront

If I go to AWS services/CloudFront, there is no distribution for this CloudFront domain at all. So I cannot edit any settings there, because it doesn't even exist. I don't think I can create it either, since it offers only S3 buckets as a source, when I try to create a distribution.

What to do? How to get CORS working?

Thank you.

ilkkah
已提問 2 年前檢視次數 422 次
1 個回答
0

It looks like x-amzn-errortype tells that request from CloudFront has not been authorized by API GW. You can configure CloudFront to convey API in the custom header sent to Origin (API GW in this case): https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/add-origin-custom-headers.html

AWS
已回答 2 年前
  • Can you elaborate - should I configure API Gateway or CloudFront?

    One problem is that on CloudFront I don't have any "distribution". Everything seems to work without a distribution for me. And I'm not sure I can just create one either, everything has been working like that for quite a while already.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南