Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Can't connect to MySQL server in lambda

import pymysql
from botocore.vendored import requests
def lambda_handler(event,context):
      conn=pymysql.connect (host ="rootrestdatabase.cd6kbmibgfod.ap-south-1.rds.amazonaws.com", user="****" , passwd="*****",db="restawsdatabase")

i want to connect rds in lambda . but i gor error like

"errorMessage": "(2003, \"Can't connect to MySQL server on 'rootrestdatabase.cd6kbmibgfod.ap-south-1.rds.amazonaws.com' (timed out)\")",
  "errorType": "OperationalError",
  "stackTrace": [
    [

i have tried it in local machine it works fine but when i deploy code in lamba it didnt worked. also both lambda function and rds are in same region. what shoud i have to do?

like image 511
Primit Avatar asked Oct 25 '25 15:10

Primit


1 Answers

To communicate with RDS instances, lambda functions have to be in the same VPC - a network timeout error is a great indicator of that. However, if your RDS instance is publicly accessible, make sure the security groups, which you attached to the function, allow traffic that you need.

like image 137
Vladyslav Usenko Avatar answered Oct 28 '25 07:10

Vladyslav Usenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!