如何连接 AWS RDS - Aurora 与 AWS Lambda Java 函数
How to hook up AWS RDS - Aurora with AWS Lambda Java function
我正在尝试将 AWS RDS Aurora 数据库与 AWS Lambda Java 函数连接起来。为此,我还没有看到任何具体的例子。我看过一些例子,但它们不是 java。
我还想用 Aurora 配置 mySQL DBMS 工具,但我做不到 :( 有人能帮我吗?我从 https://console.aws.amazon.com/rds/home?region=us-east-1#dbinstances.
此外,我尝试通过 Lambda Java 连接到数据库的代码是:
private Statement createConnection(Context context) {
logger = context.getLogger();
try {
String url = "jdbc:mysql://HOSTNAME:3306";
String username = "USERNAME";
String password = "PASSWORD";
Connection conn = DriverManager.getConnection(url, username, password);
return conn.createStatement();
} catch (Exception e) {
e.printStackTrace();
logger.log("Caught exception: " + e.getMessage());
}
return null;
}
是的,这没有帮助,因为我总是使用数据库实例配置得到 null。
RDS 需要在一个安全组中,该安全组将数据库端口打开到附加到 lambda 的 ENI 的安全组。
To enable your Lambda function to access resources inside your private VPC, you must provide additional VPC-specific configuration
information that includes VPC subnet IDs and security group IDs. AWS
Lambda uses this information to set up elastic network interfaces
(ENIs) that enable your function to connect securely to other
resources within your private VPC.
http://docs.aws.amazon.com/lambda/latest/dg/vpc.html
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html
我正在尝试将 AWS RDS Aurora 数据库与 AWS Lambda Java 函数连接起来。为此,我还没有看到任何具体的例子。我看过一些例子,但它们不是 java。
我还想用 Aurora 配置 mySQL DBMS 工具,但我做不到 :( 有人能帮我吗?我从 https://console.aws.amazon.com/rds/home?region=us-east-1#dbinstances.
此外,我尝试通过 Lambda Java 连接到数据库的代码是:
private Statement createConnection(Context context) {
logger = context.getLogger();
try {
String url = "jdbc:mysql://HOSTNAME:3306";
String username = "USERNAME";
String password = "PASSWORD";
Connection conn = DriverManager.getConnection(url, username, password);
return conn.createStatement();
} catch (Exception e) {
e.printStackTrace();
logger.log("Caught exception: " + e.getMessage());
}
return null;
}
是的,这没有帮助,因为我总是使用数据库实例配置得到 null。
RDS 需要在一个安全组中,该安全组将数据库端口打开到附加到 lambda 的 ENI 的安全组。
To enable your Lambda function to access resources inside your private VPC, you must provide additional VPC-specific configuration information that includes VPC subnet IDs and security group IDs. AWS Lambda uses this information to set up elastic network interfaces (ENIs) that enable your function to connect securely to other resources within your private VPC.
http://docs.aws.amazon.com/lambda/latest/dg/vpc.html
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html