Use a Regions
enum instead of a string to specify an AWS Region. This can minimize the risk of error.
1public void createS3ClientNoncompliant() {
2 // Noncompliant: a string is used to specify AWS region.
3 AmazonS3 s3 = AmazonS3ClientBuilder.standard()
4 .withRegion("us-west-2")
5 .build();
6}
1public void createS3ClientCompliant() {
2 // Compliant: Regions enum is used to specify AWS region.
3 AmazonS3 s3 = AmazonS3ClientBuilder.standard()
4 .withRegion(Regions.US_WEST_2)
5 .build();
6}