我有一个使用Spring Cloud AWS的Spring Boot应用程序。我正在使用Amazon RDS数据库在Elastic Beanstalk上部署应用程序。
根据the documentation,Elastic Beanstalk为您在部署应用程序时为其创建的AWS资源提供固定资源名称。
这意味着我应该能够使用Elastic Beanstalk资源名称axxt7bi97gbjy4
,而不是通过其实际实例ID(类似AWSEBRDSDatabase
)引用RDS数据库。我想这样做的原因是,克隆Elastic Beanstalk环境实际上无需手动干预即可配置正确的数据库。
问题:
当我使用Elastic Beanstalk固定资源名称AWSEBRDSDatabase
配置我的Spring Boot / Spring Cloud应用程序的数据源时...
cloud.aws.stack.auto=false
cloud.aws.region.auto=true
cloud.aws.credentials.instanceProfile=true
cloud.aws.rds.AWSEBRDSDatabase.username=user
cloud.aws.rds.AWSEBRDSDatabase.password=password
cloud.aws.rds.AWSEBRDSDatabase.databaseName=ebdb
...我收到以下异常......
Caused by: java.lang.IllegalStateException: No database instance with id:'AWSEBRDSDatabase' found. Please specify a valid db instance
at org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean.getDbInstance(AmazonRdsDataSourceFactoryBean.java:170) ~[spring-cloud-aws-jdbc-1.0.4.RELEASE.jar!/:1.0.4.RELEASE]
at org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean.createDataSourceInstance(AmazonRdsDataSourceFactoryBean.java:151) ~[spring-cloud-aws-jdbc-1.0.4.RELEASE.jar!/:1.0.4.RELEASE]
at org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean.createInstance(AmazonRdsDataSourceFactoryBean.java:129) ~[spring-cloud-aws-jdbc-1.0.4.RELEASE.jar!/:1.0.4.RELEASE]
at org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean.createInstance(AmazonRdsDataSourceFactoryBean.java:45) ~[spring-cloud-aws-jdbc-1.0.4.RELEASE.jar!/:1.0.4.RELEASE]
at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:134) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
...
当我使用对特定RDS实例的引用配置数据源时:
cloud.aws.stack.auto=false
cloud.aws.region.auto=true
cloud.aws.credentials.instanceProfile=true
cloud.aws.rds.axxt7bi97gbjy4.username=user
cloud.aws.rds.axxt7bi97gbjy4.password=password
cloud.aws.rds.axxt7bi97gbjy4.databaseName=ebdb
......一切都很好。
如何修改环境以使Elastic Beanstalk固定资源名称AWSEBRDSDatabase
出现?
更新
我在.ebextensions中添加了以下内容,并使用EB CLI创建了一个新环境。没有变化,同样的错误。 AWSEBRDSDatabase资源不可用。
Resources:
AWSEBRDSDatabase:
Type: AWS::RDS::DBInstance
Properties:
AllocatedStorage: 5
DBInstanceClass: db.t2.small
DBName: test
Engine: postgres
EngineVersion: 9.3
MasterUsername: test
MasterUserPassword: testtesttest