60
votes

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?

3

3 Answers

99
votes

you can get them with:

System.getenv("NAME_OF_YOUR_ENV_VARIABLE")
4
votes

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;
0
votes

I am using this -

System.getenv("VAR_NAME");

This works pretty well.