简体   繁体   中英

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.

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)

Steps

  1. From AWS website, select & copy the environment variables into a new notepad++ file

  2. Then perform following find-&-replace in that notepad++ file

S.No. Search mode Find what Replace with
2.1 Regex [ \t]+ (nothing)
2.2 Regex ^ \\"
2.3 Regex $ \\";
  1. Select all contents and join lines (ctrl+j shortcut for notepad++)
  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:
"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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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