我在 AWS 中创建了一个可公开访问的 PostgreSQL RDS,并使用以下代码连接到它:try { DriverManager.registerDriver(new org.postgresql.Driver()); String url = "jdbc:postgresql://" + DATABASE_SERVER_NAME + ":" + DATABASE_PORT_NUMBER + "/" + DATABASE_NAME + "?user=" + DATABASE_USER + "&password=" + DATABASE_PASSWORD; try (Connection connection = DriverManager.getConnection(url)) { try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM \"" + PHANTOM_LOAD_STORE_DATABASE_TABLE_NAME + "\"")) { try (ResultSet resultSet = statement.executeQuery()) { while (resultSet.next()) { System.out.println(resultSet.getString("userid")); } } } }} catch (SQLException e) { throw new RuntimeException(e);}当它在本地运行时,它会成功连接到数据库服务器。当它在 AWS Lambda 中运行时,它无法连接并出现以下错误:org.postgresql.util.PSQLException: The connection attempt failed....Caused by: java.net.SocketTimeoutException: connect timed outlambda 不在 VPC 中并且具有角色 policy arn:aws:iam::aws:policy/AmazonRDSDataFullAccess。有人可以告诉我我做错了什么吗?
添加回答
举报
0/150
提交
取消