首页 文章

如果RDS只能访问EC2公共IP,如何从lambda连接AWS RDS

提问于
浏览
0

我在默认VPC中创建了一个AWS Lambda函数,该函数每5分钟运行一次 . Lambda函数正在 Build JDBC连接以从RDS获取数据 .

我收到以下错误:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

美国东部地区的RDS实例,Lambda和EC2位于美国西部地区

我能够在我的EC2 ubuntu机器中访问RDS,但无法访问Lambda函数中的RDS . 我的安全组允许从任何地方访问MySQL端口3306 .

1 回答

  • 0

    当您提到您可以在其默认端口3306上访问RDS MYSQL时,这意味着您也应该能够从lambda函数连接到RDS . 我还假设您正在使用任何python模块来连接lambda函数中的RDS mysql . In that case; try having the VPC configuration at lambda is same as the RDS is in .

    import pymssql
    conn = pymssql.connect(server, user, password, "tempdb", port=3306)
    cursor = conn.cursor()
    

相关问题