简体   繁体   English

在 Java 代码中访问 AWS Lambda 环境变量

[英]Accessing AWS Lambda environment variables in Java code

The AWS has introduced Environment variables for accessing in the Lambda function. AWS 在 Lambda 函数中引入了用于访问的环境变量。 I could not find any documentation which shows how to access the environment variables from the Lambda function using Java.我找不到任何说明如何使用 Java 从 Lambda 函数访问环境变量的文档。 Can anyone help me?谁能帮我?

您可以通过以下方式获取它们:

System.getenv("NAME_OF_YOUR_ENV_VARIABLE")

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.如果您使用的是 Spring Core,则可以将 PropertySourcesPlaceholderConfigurer 类初始化为 Configuration 的一部分,然后可以使用 @Value("${RESOURCE_URL}") 注释来访问环境变量。

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

@Value("${RESOURCE_URL}")
private String url;

I am using this -我正在使用这个 -

System.getenv("VAR_NAME");

This works pretty well.这很好用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM