Why is the fixed resource name AWSEBRDSDatabase not available for my Sustainable Beanstalk / Spring Cloud AWS application?

I have a Spring boot application using Spring Cloud AWS. I am deploying the application to Elastic Beanstalk using the Amazon RDS database.

According to the documentation , Elastic Beanstalk provides fixed resource names for the AWS resources that it creates for you when you deploy your application.

This means that instead of accessing the RDS database by its actual instance id (something like axxt7bi97gbjy4), I should use the elastic beanstalk resource name AWSEBRDSDatabase. The reason I would like to do this is because cloning the Elastic Beanstalk environment will actually work without manual intervention to set up the correct database.

Problem:

When I configure my Spring Boot / Spring cloud application data source using the elastic beanstalk fixed resource name AWSEBRDSDatabase...

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

... I get the following exception ...

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]
      ...

When I configure a data source with a link to a specific RDS instance:

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

... everything is fine.

How can I change my environment to get a constant resource name with elastic beanstalk AWSEBRDSDatabase?

Update

.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
+4

Source: https://habr.com/ru/post/1663696/


All Articles