0

I had a working spring boot application including unit tests. But when I added AmazonSimpleEmailService feature to project, Spring application works without a problem and sends emails, however unit tests running with mvn clean install throws exception:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.region.StaticRegionProvider]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: The region '' is not a valid region!
Caused by: java.lang.IllegalArgumentException: The region '' is not a valid region!

Note that I added aws-config.xml :

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:aws-context="http://www.springframework.org/schema/cloud/aws/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                       http://www.springframework.org/schema/cloud/aws/context
                       http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context-1.0.xsd">

  <aws-context:context-credentials>
    <aws-context:simple-credentials access-key="${cloud.aws.credentials.accessKey:}" secret-key="${cloud.aws.credentials.secretKey:}"/>
  </aws-context:context-credentials>

  <aws-context:context-region region="${cloud.aws.region.static:}"/>
</beans>

And this configuration in application.yml file:

cloud:
  aws:
    stack:
      auto: false
    region:
      static: us-west-2
      auto: false
    credentials:
      accessKey: __SomeAccessKey__
      secretKey: __SomeSecretKey__

Any ideas?

ibrahim demir
  • 421
  • 3
  • 16

1 Answers1

0

Configuring region: Like for the credentials, the Spring Cloud AWS module also supports the configuration of the region inside the Spring Boot configuration files. The region can be automatically detected or explicitly configured (e.g. in case of local tests against the AWS cloud).

cloud.aws.region.auto : true

Enables automatic region detection based on the EC2 meta data service. So make auto = true in application.yml.

Link : configuring_region

Abdul Moeez
  • 1,331
  • 2
  • 13
  • 31