amazon-web-servicesaws-regions

Need to make AWS Regions configurable in Spring Boot properties file


Existing Code :

public class AWSConfiguration
{
@Autowired
PropertyConfig property;

    public AmazonSQS getSqs()
    {
        return AmazonSQSClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
                .withRegion(Regions.US_WEST_2)
                .build();
    }
}

I want to make Regions Configured From Properties File Say : In application.properties file

awsRegion=us-west-2

and Use this property in existing code

 public AmazonSQS getSqs()
        {
            return AmazonSQSClientBuilder.standard()
                    .withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
                    .withRegion({fetch from property file})
                    .build();
        }

Solution

  • Found below solution

    @Value("${doormls.awsRegion}")
        private String regionSQS;
    
        public AmazonSQS getSqs()
        {
            return AmazonSQSClientBuilder.standard()
                    .withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
                    .withRegion(Regions.fromName(regionSQS))
                    .build();
        }