Need to make AWS Regions configurable in Spring Boot properties file

492 Views Asked by At

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();
        }
1

There are 1 best solutions below

0
On BEST ANSWER

Found below solution

@Value("${doormls.awsRegion}")
    private String regionSQS;

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