首页 > 解决方案 > Is JDBC the only option to connect to aws hosted rds from aws lambda function

问题描述

Like the title asks, im wondering if the only way of connecting to my aws hosted rds through aws lambda function in java is through a jdbc connection?

Does the aws sdk provide a way of doing this, querying the data and returning results without the need for jdbc?

I've looked through the aws api documentation but nothing is jumping out at me in terms of making a connection through the aws sdk alone, it seems to provide functions on more admin type tasks. .

The reason I ask is in the interest of speed, the jdbc connection takes a few seconds for a connection, but thought if the aws sdk could connect it may be quicker?

标签: jdbcaws-lambdaaws-sdkamazon-rdsamazon-rds-proxy

解决方案


根据您使用的数据库类型,有不同的选项。如果您想减少连接延迟,您可以考虑使用RDS 代理,它将充当数据库实例的反向代理,并有几个连接可供您使用。它还经过优化,让您可以通过 JDBC 快速建立与它的连接。

如果您使用 Aurora Serverless,您或许可以使用 Data API,它使用 AWS 开发工具包通过 HTTP 向数据库发出请求。您可以在文档中找到更多信息:使用 Data API for Aurora Serverless

您还可以始终在 lambda 函数中使用连接池,这至少会使暖 lambda 的性能更高,但对冷启动没有帮助。


推荐阅读