Reputation: 11
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:
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
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 ' : '
Is there a way we can set and load these complex environment variables in AWS Lambda similar to my local? if not what are the possible alternate approaches?
Upvotes: 1
Views: 1115
Reputation: 21
You can use __
(double underscore) instead of :
(colon), so the environment variable in lambda would be AdministratorConfig__AdministratorPassword
as the key and your myPasswordValue
as the value.
See the documentation.
Upvotes: 2