Recipe Name:
Automatic region detection by AWS
Description:
AWS can automatically detect the region from the environment
Level:
marked_information
Language:
  • java
Tags:
  • framework specific
  • AWS
  • quality
Documentation

When deploying your application to multiple regions, and when running AWS Lambda or Amazon EC2, it might be easier to allow AWS to automatically determine the region for you.

However, keep in mind that if a region is not explicitly set, and AWS is unable to determine it, the client creation will fail.

Before
Region newRegion = Region.US_EAST_1;
Ec2Client ec2 = Ec2Client.builder()
    .region(newRegion)
    .build();
After
Ec2Client ec2 = Ec2Client.create();
Resources
Recipe
id: scw:aws:automatic-region
version: 10
metadata:
  name: Automatic region detection by AWS
  shortDescription: AWS can automatically detect the region from the environment
  level: marked_information
  language: java
  enabled: true
  descriptionFile: descriptions/AutomaticregiondetectionbyAWS.html
  tags: framework specific;AWS;quality
search:
  methodcall:
    name: region
    declaration:
      type: software.amazon.awssdk.awscore.client.builder.AwsClientBuilder
availableFixes:
- name: Consult the AWS documentation page concerning region selection
  actions:
  - goto:
      type: URL
      value: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/region-selection.html
- name: Allow AWS to detect the region automatically
  actions:
  - rewrite:
      to: '{{{ qualifier }}}'