68

The AWS has introduced Environment variables for accessing in the Lambda function. I could not find any documentation which shows how to access the environment variables from the Lambda function using Java. Can anyone help me?

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Java Programmer
  • 1,347
  • 3
  • 12
  • 31

4 Answers4

117

you can get them with:

System.getenv("NAME_OF_YOUR_ENV_VARIABLE")
Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
hellomichibye
  • 4,112
  • 2
  • 23
  • 23
4

If You are using Spring Core then PropertySourcesPlaceholderConfigurer class can be initialized as a part of Configuration and then @Value("${RESOURCE_URL}") annotation can be used to access environment variables.

@Bean
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
    return new PropertySourcesPlaceholderConfigurer();
}

@Value("${RESOURCE_URL}")
private String url;
dassum
  • 4,727
  • 2
  • 25
  • 38
0

I am using this -

System.getenv("VAR_NAME");

This works pretty well.

Darren Tsai
  • 32,117
  • 5
  • 21
  • 51
0

If you define environment variable in aws lambda with key as "MyKey" and value as "XYX" then I will use:

System.getenv("MyKey");