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?

已提問 3 年前檢視次數 464 次
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 年前

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

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

回答問題指南