在 Java 代码中访问 AWS Lambda 环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41094954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Accessing AWS Lambda environment variables in Java code
提问by Java Programmer
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?
AWS 在 Lambda 函数中引入了用于访问的环境变量。我找不到任何说明如何使用 Java 从 Lambda 函数访问环境变量的文档。谁能帮我?
采纳答案by hellomichibye
you can get them with:
您可以通过以下方式获取它们:
System.getenv("NAME_OF_YOUR_ENV_VARIABLE")
回答by dassum
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;