0

I have RDS MySQL database created under one AWS account. This DB is opened, i can connect by Workbench or by any other desktop app.

Also i have other AWS account where i'm trying to create Lambda function for to connect to RDS DB from my first account.

And looks like it's impossible because i'm every time getting timeout.

Here is my Lambda Java code:

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

import java.sql.DriverManager;

public class DBTest implements RequestHandler<String, String> {

    @Override
    public String handleRequest(String input, Context context) {
        context.getLogger().log("Input: " + input+"\n");

        try {
            StringBuilder url = new StringBuilder();

            url.append("jdbc:mysql://").
                append("jackdbinstance.********.eu-west-1.rds.amazonaws.com:3306/").
                append("TestLambdaDB"+"?").
                append("user=******&").
                append("password=*******");


            DriverManager.getConnection(url.toString());

            return "DB connected";
        } catch (Exception e) {
            return e.toString();
        }
    }
} 

Using same code i can connect from my desktop java app without any problems.

I'm not using VPC, i have allocated 512Mb memory for Lambda, timeout set to 30sec(from my view it's enough)

Can somebody help please?

Yevhen
  • 791
  • 9
  • 24
  • How does workbench connect to your database? Can workbench connect to your instance's port 3306 directly (no ssh, port-forwarding, etc.)? Does that mean the entire internet can try to connect to your instance at port 3306 as well? – Noel Llevares Nov 30 '17 at 00:41
  • 3
    Did you check your VPC security group that attached in your RDS MySQL? Maybe it is blocking amazon IP addresses that being used by lamba? When you first creted RDS, by default it will create new security group and in that security group, your desktop IP address was added automatically. – Rodel Nov 30 '17 at 01:06
  • 1
    Thank's Rodel. Your answer was helpful. There was only one IP – Yevhen Nov 30 '17 at 07:36

1 Answers1

4

Problem was connected with security group config for RDS instance, there was only one IP applied for to connect, somehow this rule was set automatically when i create RDS instance.

Yevhen
  • 791
  • 9
  • 24