Use an enum to specify an AWS Region Low

Use a Regions enum instead of a string to specify an AWS Region. This can minimize the risk of error.

Detector ID
java/aws-region-enumeration@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-

Noncompliant example

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}

Compliant example

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}