If you don’t explicitly set an AWS Region, the SDK consults the default Region provider chain to determine the Region to use. This might cause a delay that causes a poor cold-start. If code portability is not an issue, consider explicitly setting the AWS Region using the withRegion method.
1public class AwsServiceClientInitializationNoncompliant implements RequestHandler<String, Void> {
2
3 private DataPipeline dataPipeline;
4
5 public void AwsServiceClientInitializationNoncompliant() {
6 // Noncompliant: AWS region provider not specified.
7 dataPipeline = DataPipelineAsyncClientBuilder.defaultClient();
8 }
9
10 @Override
11 public Void handleRequest(String requestEvent, Context context) {
12 // Handle the request here.
13 return null;
14 }
15}
1public class AwsServiceClientInitializationCompliant implements RequestHandler<String, Void> {
2
3 private DataPipeline dataPipeline;
4
5 public void AwsServiceClientInitializationCompliant() {
6 // Compliant: AWS region provider specified.
7 dataPipeline = DataPipelineAsyncClientBuilder.standard().withRegion(Regions.US_WEST_2).build();
8 }
9
10 @Override
11 public Void handleRequest(String requestEvent, Context context) {
12 // Handle the request here.
13 return null;
14 }
15}