1

I'm trying to access our servers MySQL database (Not AWS RDS) with:

def lambda_handler(event, context):
    try:
        conn = pymysql.connect("mySite.com", user="admin", passwd="pass",  connect_timeout=5)

and I'm getting return error:

Response:
{
  "errorMessage": "xxxxxxxxxxxxxxxxxxxxxxxxx Task timed out after 3.00 seconds"
}

I've set up my roles with the AWSLambdaVPCAccessExecutionRole and WSLambdaRole and set up a default VPC network with subnets and security groups:

Security group ID: sg-xxxxxxxx
Ports: All
Destination: 0.0.0.0/0  

Is there something I'm forgetting? I tested this with a RDS and I'm able to connect to the DB it's just when I try an external DB it's timing out.

enter image description here

1 Answer 1

2

If the database isn't in the VPC, then the Lambda function won't have access to it. When you run a Lambda function inside a VPC the Lambda function is not assigned a public IP address. To give it access to resources outside the VPC the Lambda function will have to be in a private subnet, with a route to a NAT Gateway.

Alternatively, if it does not need to access resources inside the VPC, then just remove it from the VPC and it will have Internet access.

If the database is in the VPC running on an EC2 server, then you probably need to open the security group assigned to the EC2 server appropriately.

Sign up to request clarification or add additional context in comments.

7 Comments

I originally was running without the VPC, but to test with the RDS I added one, I'm still getting the timeout error after removing the VPC. Any other ideas? I don't need access to a RDS I need access to a remote DB.
Is your database server actually accessible from the Internet? At this point it sounds like a networking issue on the database end.
Hey Mark, sorry I've been caught up. I'm able to access the server through SSH with a public/private key so I don't think it's not accessible, and I would have assumed this would just throw up a connection error if the credentials are not found or missing, so can you suggest anything else?
Accessing the server through SSH doesn't mean the firewall(s) in front of the server allow direct connections to the database. You need to test connecting to the database from the Internet, like via some software on your laptop, to verify it is accessible.
I have the same problem here.I am in the staging VPC with all subnets, and I am in the staging security group. Still I can not get access, and I am not getting any error messages just timing out.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.