santhosh
santhosh

Reputation: 61

Python AWS lambda function connecting to RDS mysql: Timeout error

When the python lambda function is executed I get "Task timed out after 3.00 seconds" error. I am trying the same example function. When I try to run the same code from eclipse it works fine and I can see the query result. Same way I can connect to the db instance from local-machine Mysql workbench without any issues.
I tried creating a role with with full administrator access policy for this lambda function and even then its not working fine. The db instance has a vpc and I just added my local ip address there using the edit CIDR option so I can access the instance through my local machine workbench. For VPC, subnet and security group parameter in lambda function I gave the same values as I have in the RDS db instance. I have also increased the timeout for lambda function and still I see the timeout error.
Any input would be appreciated.

Upvotes: 3

Views: 3548

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179364

For VPC, subnet and security group parameter in lambda function I gave the same values as I have in the RDS db instance.

Security groups don't automatically trust their own members to access other members.

Add a rule to this security group for "MySQL" (TCP port 3306) but instead of specifying an IP address, start typing s g into the box and select the id of the security group that you are adding the rule to -- so that the group is self-referential.

Note that this is probably not the correct long-term fix, because if your Lambda function needs to access the Internet or most AWS services, the Lambda function needs to be on a private subnet behind a NAT device. That does not describe the configuration of the subnet where your RDS instance is currently configured, because you mentioned adding your local IP to allow access to RDS. That suggests your RDS is on a public subnet.

See also Why Do We Need Private Subnets in VPC for a better understanding of public vs. private subnets.

Upvotes: 3

Related Questions