Invoke Lambda via function URL inside VPC

454 Views Asked by At

I am running an app that uses an API running inside a Lambda to serve HTTP requests. Currently requests come in via API gateway, API gateway invokes the Lambda, the Lambda connects to a database and gets the requested information and returns it. This is working well. The issue I have run into is that API Gateway has a request size of 10MB. Due to this I am looking to remove API gateway and use a reverse proxy running on a public EC2 instance.

The issue I am facing is trying to work out the best way to go about this. As I am no longer invoking the lambda via API gateway I figured that a Function URL would be the way to go.

The way I envision the setup would be:

Lambda - In VPC with a private subnet

Database - In VPC with a private subnet

EC2 Instance - In VPC with a public subnet

I have got this setup and I have connected an Internet Gateway to the public subnet and a NAT Gateway to the Private subnet.

The problem is that I cannot seem to call Lambda via the Function URL from the EC2 instance. I have also tried putting the Lambda in the Public Subnet, removing the NAT Gateway from the equation, but still no luck. Everytime the function URL just returns 301.

If I take the Lambda out of the VPC I can call it via the Function URL but it cannot connect to the DB (which makes sense).

I have checked the Security Groups on the Lambda and the VPC and cannot see any issues.

Here are some screenshots of the setup when the Lambda is in the public Subnet incase I have just completely missed something:

enter image description here

enter image description here

enter image description here

0

There are 0 best solutions below