[英]How to set environment variables for complex configuration parameters in AWS lambda using asp.net core 3.1 serverless?
In my asp.net core 3.1 web API launchsettings.json
I have a environment variable named "AdminstratorConfig:AdminstratorPassword": "myPasswordValue"
In my asp.net core 3.1 web API launchsettings.json
I have a environment variable named "AdminstratorConfig:AdminstratorPassword": "myPasswordValue"
Now in my code I also have a class named AppSettings
defined like this:现在在我的代码中,我还有一个名为AppSettings
的 class 定义如下:
public class AppSettings
{
public AdminstratorConfiguration AdminstratorConfig { get; set; }
}
public class AdminstratorConfiguration
{
public string AdminstratorPassword { get; set; }
}
When running in my local I can bind the environment variable into my AppSettings instance using something like this in the Startup
在本地运行时,我可以在Startup
中使用类似的东西将环境变量绑定到我的AppSettings实例中
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
var appSettings = new AppSettings();
Configuration.Bind(appSettings);
// Here appSettings.AdminstratorConfig.AdminstratorPassword contains value 'myPasswordValue'
}
}
I cal also load the same from my appsettings.json if I have my configuration defined as如果我的配置定义为
{
"AdminstratorConfig":
{
"AdminstratorPassword": "myPasswordValue"
}
}
However after deploying my application as AWS serverless lambda I tried to set the same environment variable in Lambda configuration section but it doesn't allow special characters here ' : '但是,在将我的应用程序部署为 AWS 无服务器 lambda 后,我尝试在 Lambda 配置部分设置相同的环境变量,但此处不允许使用特殊字符“ : ”
Is there a way we can set and load these complex environment variables in AWS Lambda similar to my local?有没有一种方法可以像我的本地一样在 AWS Lambda 中设置和加载这些复杂的环境变量? if not what are the possible alternate approaches?如果不是,可能的替代方法是什么?
You can use __ (double underscore) instead of: (colon), so the environment variable in lambda would be: "AdministratorConfig__AdministratorPassword" as key and your "myPasswordValue" as value.您可以使用 __(双下划线)代替:(冒号),因此 lambda 中的环境变量将为:“AdministratorConfig__AdministratorPassword”作为键,您的“myPasswordValue”作为值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.