API Gateway, Lambda and CORS

0

I am running a few Lambda functions behind a load balancer (i.e. the Load Balancer is the Lambda Function's "source") which I intend to access from a web based SPA. I'm using API Gateway to proxy requests to my load balancer for other services (containers on ECS), and i was hoping to do the same for my Lambda functions.

I've spent the past 2 days dealing with CORS issues with my containerized applications, and so, to avoid that when it comes to my lambda functions, I decided to ask here what might be the best path going forward.

I cannot use the Lambda Proxy integration on API Gateway. It tells me that I do not have any Lambda Functions in my region (I assume this may be because the Lambda functions are deployed in a VPC, but i am not 100% sure on that).

So, is it possible to access Lambda Functions via a Load Balancer through API Gateway proxy+ resources? My intuition says yes, but I'm running into CORS issues. If so, how can I manage CORS in this scenario?

2개 답변
1

To avoid CORS, i've had to create my own OPTIONS handler for each function. The cheapest is just to echo the ORIGIN header back as authorized via CORS. The better way is to have the api gateway on the same domain as the rest of the product. So in order to get rid of CORS errors I've used Cloudfront to forward requests to the API gateway.

The explanation of your setup is a little vague, it shouldn't matter if its in a container or not. CORS is all about browser action and if you are accessing a resource outside of the domain of your main web page.

If you are using a program outside of a web browser-like interface then you wouldn't have any CORS issues.

Rahly
답변함 3년 전
-2

Don't bother answering.

This product is effectively unusable. I will find another solution.

답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠