Override of reserved variable names in a Lambda function High

Overriding environment variables that are reserved by AWS Lambda might lead to unexpected behavior or failure of the Lambda function.

Detector ID
java/lambda-override-reserved@v1.0
Category

Noncompliant example

1public class LambdaOverrideReservedNoncompliant implements RequestHandler<String, Void> {
2    public Void handleRequest(String requestEvent, Context context) {
3        final Map<String, String> environment = new ProcessBuilder().environment();
4        // Noncompliant: overrides reserved environment variable names in a Lambda function.
5        environment.put("AWS_REGION", "us-west-2");
6        return null;
7    }
8}

Compliant example

1public class LambdaOverrideReservedCompliant implements RequestHandler<String, Void> {
2    public Void handleRequest(String requestEvent, Context context) {
3        final Map<String, String> environment = new ProcessBuilder().environment();
4        // Compliant: does not override any reserved environment variable names in a Lambda function.
5        environment.put("LANG", "en_US.UTF-8");
6        return null;
7    }
8}