Skip to content

502 Bad Gateway for API Gateway and Lambda within our new AWS VPC when running JS code that executes SQL

0

We have an AWS Lambda function running JS code, which executes a SQL query to get data from our on-prem DB.

When we trigger the lambda function using an Amazon API Gateway endpoint, we get an expected connectivity error, because we need to whitelist the IP address.

And so we created a VPC with a static IP address, which we then whitelisted for our on-prem network so it could access data from our on-prem database over a specific port.

However, now when we trigger the Lambda function via Amazon API Gateway, we get a 502 Bad Gateway error.

We have ensured that we are whitelisting the correct IP address and we believe there are not any permissions issues related to the execution role of the lambda function.

What are some common issues with the VPC configuration that we maybe are missing?

Any help is very appreciated. Thank you.

Ryan Farran 480-734-6450

1 Answer
1

Hi fmdev,

Please try thie solution it will be helpful for you.

Step:1 Verify VPC Configuration:

Subnets and Route table

  1. the Lambda function is placed in the correct subnets.
  
  2. Verify that these subnets have route tables configured to direct traffic to the 
          NAT Gateway, Internet Gateway, or VPN gateway if needed.

Step:2 Check Security Groups:

Outbound Rules for Lambda:

    1.the security group attached to the Lambda function allows outbound traffic on 
        the necessary ports to your on-premises database.

Inbound Rules for Database:

    1.on-premises database's firewall/security group allows inbound traffic from the 
        IP range of your VPC or the specific IP address if you're using a NAT Gateway 
        with a static IP.

Step:3 NAT Gateway and Internet Gateway:

Setup NAT Gateway:

      1.If your Lambda function needs internet access (to download dependencies), 
         ensure it is configured to route through a NAT Gateway in a public subnet.

Configure Route Tables:

      1.the route tables in the private subnets where your Lambda resides route 
         internet-bound traffic through the NAT Gateway.

Please look at AWS Document Link you will get more information.

https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html

EXPERT
answered 2 years ago
EXPERT
reviewed 2 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.