从 .env 文件访问 Lambda 环境变量

Access Lambda environment variables from .env file

我是 运行 .net core 3.1 AWS Lambda 函数,但我无法使用 c# 从 AWS Lambda 控制台访问环境变量:

var envVariable = Environment.GetEnvironmentVariable("myVariableName");

环境变量存储在我的 lambda 函数根目录下的 .env 文件中。是否需要将 .env 文件复制到构建文件夹中才能在 lambda 函数中访问它?如何从 .env 文件访问 AWS Lambda 环境变量?

应用程序结构

cloudformation-template.json指的是.env文件。

更新:2020 年 5 月 31 日:

我删除了 .env 文件并将 cloudformation-template.json 中的变量直接添加为单独的变量。当我尝试使用 amplify publish 命令将其推送到 aws 时,我得到一个

Resource is not in the state stackUpdateComplete
An error occured during the push operation: Resource is not in the state stackUpdateComplete error

我可以通过将环境变量直接添加到cloudformation-template.json和运行 amplify publish命令来推送到aws来解决这个问题。

"Environment": {
                    "Variables": {                      
                        "VUE_APP_STRIPE_PUBLISHABLE_KEY": "<someRandomString>",
                        "VUE_APP_STRIPE_SECRET_KEY": "<someRandomString>"
                    }
                },