简体   繁体   English

如何使用 asp.net core 3.1 serverless 在 AWS lambda 中为复杂的配置参数设置环境变量?

[英]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.

相关问题 aws lambda function 使用 asp.net 核心的无服务器模板 - aws lambda function using serverless template of asp.net core 为ASP.NET Core lambda函数serverless.template文件设置AWS Authorizer条目 - Set AWS Authorizer entry for ASP.NET Core lambda function serverless.template file 将自定义 AWS Lambda 运行时与 asp.net 核心结合使用 - Using Custom AWS Lambda Runtimes with asp.net core 如何使用无服务器框架通过 AWS Lambda Function 环境变量访问 SSM 参数存储值? - How to access SSM Parameter Store Values through AWS Lambda Function Environment Variables using Serverless Framework? 如何使用Python在AWS Lambda中设置环境变量 - How to set environment variables in AWS lambda using Python AWS Lambda-使用.NET Core构建无服务器API - AWS Lambda - Building serverless API using .NET Core ASP.NET AWS 无服务器 - ASP.NET AWS Serverless Error publishing ASP.NET Core Web API to AWS Serverless Lambda: 'AWSLambdaFullAccess' at 'policyArn' … Member must have length greater than - Error publishing ASP.NET Core Web API to AWS Serverless Lambda: 'AWSLambdaFullAccess' at 'policyArn' … Member must have length greater than 如何使用适用于AWS Lambda的无服务器部署来部署环境变量 - How to deploy environment variable using serverless deploy for AWS lambda AWS .NET Core 3.1 Mock Lambda 测试工具-如何设置2个或更多函数进行本地测试 - AWS .NET Core 3.1 Mock Lambda Test Tool - How to set up 2 or more functions for local testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM