I am trying to access a MySQL database on Amazon RDS from an AWS Lambda Python function. After running test, it give a error of connection failed:
"errorMessage": "2019-05-27T15:14:26.967Z f6e8ae8d-1dfc-4be5-9e00-a2c937e4ca2c Task timed out after 3.00 seconds"
I believe that is cause by the configuration of VPC or NAT or Security Group.
I tried to follow:
- AWS Lambda: Enable Outgoing Internet Access within VPC
- Tutorial: Configuring a Lambda Function to Access Amazon RDS in an Amazon VPC - AWS Lambda
But still not working
I have:
- A default VPC with one Internet Gateway attached
- 2 subnets with IPv4 CIDR
xxx.xx.0.0/20
(subnet001) andxxx.xx.16.0/20
(subnet002) associated with one route table and one Network ACL. - NAT Gateway associate with subnet001
My question is:
According to these two tutorials, I will need one VPC, four subnets (1,2,3,4), first two subnets associate with the main route table that access to local and internet gateway. And second two subnets associate with "lambda-to-internet" route table that access to local and a NAT gateway.
The NAT gateway should associate with subnet 1. Am I correct?
And for network ACL, do all four subnets associate with same ACL?
In Lambda VPC setting, do I add all four subnets or only last two subnets?
rds_host = "my_host_name"
name = "my_username"
password = "my_password"
db_name = "my_db_name"
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5)