aws-toolkit-jetbrains icon indicating copy to clipboard operation
aws-toolkit-jetbrains copied to clipboard

Lambda Local Run should support reading environment variables from a file

Open kiiadi opened this issue 4 years ago • 6 comments

you can't setup env variables, or define the location of your requirements file

source: https://plugins.jetbrains.com/plugin/11349-aws-toolkit/reviews#review=44513

kiiadi avatar Aug 31 '20 19:08 kiiadi

When invoking lambda's locally you should be able to define Environment Variables as part of the Run Configuration (see attached) - is this what you're looking for?

Interested in a bit more information about the requirements.txt - do you have a SAM/CloudFormation template?

Screen Shot 2020-08-31 at 12 21 43 PM

kiiadi avatar Aug 31 '20 19:08 kiiadi

JetBrains has changed the display of env vars, we have diverged. They now always show it with a white background to indicate editable

Screen Shot 2020-08-31 at 12 26 48 PM

abrooksv avatar Aug 31 '20 19:08 abrooksv

Good call

kiiadi avatar Aug 31 '20 19:08 kiiadi

Hi, I don't see the Environment input white and its only editable clicking the icon, so though it wasn't editable sorry. I have a cfn template, by default the plugin finds requirements in the folder of CodeUri, where is the lambda code. It's nice, but my requirements file is shared with other lambdas, so I would like to have it outside that folder, anyway it's not a big problem, to copy it to the folder for run lambda correctly but of course it would be awesome to be able to configure the location of it, but my main problem was I couldn't find how to set the environment variables, so I couldn't use the plugin.

Btw, Is it possible a feature to configure for get environment variables from a .env file? setup manually all environment variables to every lambda of the template is very annoying.

jordisantamaria avatar Sep 04 '20 14:09 jordisantamaria

Sorry for the delay in responding.

my requirements file is shared with other lambdas, so I would like to have it outside that folder

The toolkit uses the AWS SAM CLI to build the lambda package - by default it looks for the requirements.txt at the base of the module (e.g. the CodeUri directory) - however it is possible to override this behaviour in the run configuration:

  1. From the Local Lambda invoke run configuration, select the "SAM CLI" tab
  2. The Build Args box allows you to specify additional parameters to pass to the sam build command (docs)
  3. To point to a different location you want the --manifest argument and then the location of the requirements.txt

Screen Shot 2020-09-10 at 4 00 54 PM

Is it possible a feature to configure for get environment variables from a .env file

Would you see this as a one-time import from the .env file? or would you want the run-configuration to point at the file itself and re-load it on every invocation - that way changes to the file would automatically get picked up? It would be great if you could open a new feature request and include a little more detail on what the experience would be like.

kiiadi avatar Sep 10 '20 23:09 kiiadi

I see, thanks for the response.

I really would like the run-configuration to point by default to the .env file and re-load it in every invocation of course, so If I want to run lambda in other environment, I just can change .env file params, and them running lambda again, its running with the new params.

And it should be able to configure the path to .env file, since for example, I have cloudformation files in cfn folder, not in root folder with the .env file.

jordisantamaria avatar Sep 12 '20 04:09 jordisantamaria