By using AWS re:Post, you agree to the AWS re:Post Terms of Use

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 Answers
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.

answered 4 years ago
-2

Don't bother answering.

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

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions