Visual Studio 如何将环境变量从一个 AWS lambda 复制到另一个

How to copy environment variables from one AWS lambda to another in Visual Studio

我想将现有 AWS lambda 中已经存在的环境变量模拟到我在 Visual Studio IDE.

中创建的新 AWS lambda 中

我没有找到导出/导入环境变量的方法,所以想知道如何最大程度地减少手动工作(再次手动创建每个环境变量)

因为我没有找到任何 export/import 选项 - 无论是在 AWS 门户中还是通过 Visual studio 中显示的 AWS 资源管理器,我都求助于 Notepad++ copy/paste/regex-ing 以便我可以填充aws-lambda-tools-defaults.json 可以在 Visual Studio 中进行配置(这将使用在该 .json 文件中设置的环境变量发布 lambda)

步骤

  1. 来自 AWS 网站,select & 将环境变量复制到一个新的记事本++文件中

  2. 然后在记事本++文件中执行以下查找和替换

S.No. Search mode Find what Replace with
2.1 Regex [ \t]+ (nothing)
2.2 Regex ^ \"
2.3 Regex $ \";
  1. Select所有内容和连接行(记事本++的快捷键ctrl+j)
  2. 删除上一步引入的分号之间的空格(将 ; 替换为 ;

现在可以将生成的单行输出粘贴到 aws json 文件中的占位符处:
“环境变量”:“<place the outcome here>”,
(注意:结果文本周围的双引号应该保留在那里)

现在,当您保存 aws json 文件并从 Visual Studio IDE 发布此 lambda 时,您将看到预填充的环境变量