I have a NodeJS Rest API that is deployed on AWS throught Serverless, which automatically creates a Lambda function and a API on API Gateway for me.
Every time I try to make a HTTPS request to any external APIs, I get an error from API Gateway (502 - Internal Server Error), even thought everything works fine when I'm testing in my local PC. And the error only happens if I call the route that makes the external request, so I'm sure that's the problem.
I've already activated API Gateway logs with Cloudwatch (following this post), but the only important log I get is Endpoint response body before transformations: {"errorMessage":"2020-10-21T18:34:14.038Z 4cf0e078-fec9-4b9c-a199-26216a3951aa Task timed out after 6.01 seconds"}
(complete logs in that image). The Lambda logs are less detailed, but here they are.
I also have set up a VPC and a Security Group for my Lambda function. My Security Group already alows all trafic for both inbound and outbound rules. My VPC may be the problem, since I don't understand very much about subnets and the configurations I got there. These are my Lambda VPC configurations.
Can someone tell me what's the problem? I'm available to add any more information that you may want/need.
--------- Edit 1:
I tried to follow the steps of this post, but it didn't work. Let me explain everything I did:
First of all, I created a NAT Gateway to my VPC and a new Route Table with the 0.0.0.0/0 destination routed to this NAT Gateway. Then I created a Public Subnet, assigned the new Route Table to it and turned on the Enable auto-assign public IPv4 address
option. Finally, I assigned this new Public Subnet to my Lambda function, but the error was still there. I also tried to remove the Public Subnet from the Lambda function, 'cause someone said it would work on the post, but it still didn't work.
The only thing I couldn't do was to set my new Public Subnet as a default subnet. I don't know if it was a core thing to do and if it only didn't work because of that.
Am I forgetting something?