
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
67 lines
2.1 KiB
Plaintext
67 lines
2.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
If the region is not specified when creating a new AwsClient with an https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/awscore/client/builder/AwsClientBuilder.html[AwsClientBuilder], the AWS SDK will execute some logic to identify the endpoint automatically.
|
|
|
|
While it will probably identify the correct one, this extra logic will slow down startup time, already known to be a hotspot.
|
|
|
|
You should therefore always define the logic to set the region yourself. This is typically done by retrieving the region from the Lambda provided AWS_REGION environment variable.
|
|
|
|
This will make the code more explicit and spare initialization time.
|
|
|
|
|
|
This rule reports an issue when the region is not set when creating an AwsClient.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
S3Client.builder()
|
|
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
|
|
.build();
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
S3Client.builder()
|
|
.region(Region.of(System.getenv(SdkSystemSetting.AWS_REGION.environmentVariable()))
|
|
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
|
|
.build();
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://aws.amazon.com/fr/blogs/developer/tuning-the-aws-java-sdk-2-x-to-reduce-startup-time/[Tuning the AWS Java SDK 2.x to reduce startup time]
|
|
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/lambda-optimize-starttime.html[Optimizing cold start performance for AWS Lambda]
|
|
* https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html[Environment variable configuration]
|
|
* https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-region-selection.html#automatically-determine-the-aws-region-from-the-environment[Automatically Determine the AWS Region]
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Set the region explicitly on this builder.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
AwsClient builder.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== is related to: S6242
|
|
|
|
endif::env-github,rspecator-view[]
|