【发布时间】:2022-07-21 22:32:51
【问题描述】:
在我的 asp.net core 3.1 Web API launchsettings.json 我有一个名为 "AdminstratorConfig:AdminstratorPassword": "myPasswordValue" 的环境变量
现在在我的代码中,我还有一个名为 AppSettings 的类,定义如下:
public class AppSettings
{
public AdminstratorConfiguration AdminstratorConfig { get; set; }
}
public class AdminstratorConfiguration
{
public string AdminstratorPassword { get; set; }
}
在我的 local 中运行时,我可以在 Startup
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'
}
}
如果我的配置定义为
,我也会从我的 appsettings.json 加载相同的内容{
"AdminstratorConfig":
{
"AdminstratorPassword": "myPasswordValue"
}
}
但是,在将我的应用程序部署为 AWS 无服务器 lambda 后,我尝试在 Lambda 配置部分设置相同的环境变量,但此处不允许使用特殊字符“:”
有没有一种方法可以像我的本地一样在 AWS Lambda 中设置和加载这些复杂的环境变量? 如果不是,还有哪些可能的替代方法?
【问题讨论】:
-
参考这篇文章,可能有帮助:aws.amazon.com/blogs/developer/…
-
请在您的问题中添加您的 aws sam 模板文件
标签: amazon-web-services asp.net-core aws-lambda aws-serverless aws-sam