如何在elastic beanstalk中将PostgreSQL RDS连接到Spring Boot?

问题描述 投票:0回答:3

我有一个 Spring Boot 应用程序,它已经可以连接到我的笔记本电脑中的本地 Postgres。我将 spring boot jar 文件上传到 elastic beanstalk,它部署得很好,我可以看到应用程序中的所有内容,除了它无法连接到我在 RDS 中创建的 Postgres 数据库。

我尝试将 rds 数据库实例名称的数据库标识符和主密码放入应用程序属性文件中,但不起作用。

#cloud.aws.rds.mydbinstanceidentifier
#cloud.aws.rds.testdbspringiloilo.password=mydbmasterpassword

当我尝试请求来自数据库的对象时,它会显示一个白标签页面,告诉我它超时了。

postgresql amazon-web-services spring-boot amazon-elastic-beanstalk
3个回答
0
投票

您的应用程序无法到达 RDS 实例并且超时。请确保:

1- 安全组有一个入口规则,允许在数据库端口(Postgres 默认为 5432)上形成应用程序的子网/安全组的连接
2- 启动 RDS 实例的子网的访问列表允许从 Beanstalk 环境传入的流量。
3- 您在属性文件中配置了正确的端点和端口。

还可以考虑使用环境变量来保存您的机密,而不是将它们作为纯文本存储在应用程序文件中。


0
投票

好的,这就是我解决问题的方法。我不知道其中哪一个实际上解决了这个问题。

  1. 我添加了一条新规则以在 vpc 中打开端口 5432。 (这让我很困惑,因为我明确添加了 Postgres rds 快照,所以执行脚本时配置页面不应该这样做吗?)

  2. 我向 pom 文件添加了一个新的依赖项,我不太确定这是否真的很重要,因为我已经可以运行该应用程序,但无法连接到数据库。

    org.springframework.boot spring-boot-starter-web

  3. 我没有使用数据库标识符,而是使用快照的端点地址。

感谢所有参与的人!干杯!


0
投票

您尝试使用 cloud.aws.rds 配置,但不使用 Spring Cloud AWS。

您需要额外的依赖项:

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-aws</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-aws-jdbc</artifactId>
    </dependency>

更多关于 Spring Cloud AWS 的内容请阅读官方文档: https://spring.io/projects/spring-cloud-aws

还有一个很好的示例:https://github.com/codeurjc/spring-cloud-aws-sample

© www.soinside.com 2019 - 2024. All rights reserved.