简体   繁体   English

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

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

I want to mimic environment variables that already exist in an existing AWS lambda into a new AWS lambda I am creating in Visual Studio IDE.我想将现有 AWS lambda 中已经存在的环境变量模拟到我在 Visual Studio IDE 中创建的新 AWS lambda 中。

I did not find a way to export / import environment variables so was wondering how to minimize manual effort (of manually creating each environment variable again)我没有找到导出/导入环境变量的方法,所以想知道如何最大限度地减少手动工作(再次手动创建每个环境变量)

As I did not find any export/import option - neither in AWS portal nor via AWS explorer that shows in Visual studio, I resorted to Notepad++ copy/paste/regex-ing so that I could populate the aws-lambda-tools-defaults.json that can be configured in Visual Studio (which will publish the lambda with the environment variables as set in that.json file)由于我没有找到任何导出/导入选项 - 无论是在 AWS 门户中还是通过 Visual Studio 中显示的 AWS 资源管理器,我都使用了 Notepad++ 复制/粘贴/正则表达式,以便我可以填充 aws-lambda-tools-defaults。可以在 Visual Studio 中配置的 json(它将发布 lambda,环境变量在 that.json 文件中设置)

Steps脚步

  1. From AWS website, select & copy the environment variables into a new notepad++ file从 AWS 网站,select 并将环境变量复制到一个新的记事本++文件中

  2. Then perform following find-&-replace in that notepad++ file然后在该记事本++文件中执行以下查找-替换

S.No.编号 Search mode搜索模式 Find what找什么 Replace with用。。。来代替
2.1 2.1 Regex正则表达式 [ \t]+ (nothing) (没有什么)
2.2 2.2 Regex正则表达式 ^ \\"
2.3 2.3 Regex正则表达式 $ \\";
  1. Select all contents and join lines (ctrl+j shortcut for notepad++) Select 所有内容和连接线(记事本++的 ctrl+j 快捷方式)
  2. Remove whitespace between semicolons introduced by previous step (replace ; with ; )删除上一步引入的分号之间的空格(将;替换为;

The single line output that gets produced can now be pasted at the placeholder in the aws json file:现在可以将生成的单行 output 粘贴到 aws json 文件中的占位符处:
"environment-variables": " <place the outcome here> ", "environment-variables": " <place the outcome here> ",
(note: the double quotes surrounding the outcome text should remain there) (注意:结果文本周围的双引号应保留在那里)

Now when you save the aws json file and publish this lambda from Visual Studio IDE, you will see the environment variables prefilled现在,当您保存 aws json 文件并从 Visual Studio IDE 发布此 lambda 时,您将看到预填充的环境变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM