Parth Pithadia
Parth Pithadia

Reputation: 306

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

Upvotes: 0

Views: 551

Answers (1)

Parth Pithadia
Parth Pithadia

Reputation: 306

Found below solution

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

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

Upvotes: 1

Related Questions