Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set "environmentVariables": {} in templates.json #795

Closed
pcharasala opened this issue Oct 23, 2019 · 2 comments
Closed

How to set "environmentVariables": {} in templates.json #795

pcharasala opened this issue Oct 23, 2019 · 2 comments
Labels
guidance General information and guidance, answers to FAQs, or recommended best practices/resources. sam

Comments

@pcharasala
Copy link

Have been looking for help hours on how to set "environmentVariables": {} in .aws templates.json.
Have tried "environmentVariables": {"key":"value"}
"environmentVariables": {"Variablkes":[{"key":"value"}]}
"environmentVariables": [{"key":"value"},]

None works.
Please help.

@awschristou
Copy link
Contributor

Hi @pcharasala the proper configuration is "environmentVariables": {"key":"value"} , however the environment variable must also be defined in your SAM Template file.

Here is an example...

My SAM Template (template.yaml) file has the following resource that contains an environment variable called SAMPLE1:

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandlerN10
      Runtime: nodejs10.x
      Environment:
        Variables:
          SAMPLE1: Default Sample 1 Value

My configuration for environment variables looks like this:

          "environmentVariables": {
              "SAMPLE1": "My sample 1 value"
          }

Can you please check your template and configuration and report back?

@awschristou awschristou added guidance General information and guidance, answers to FAQs, or recommended best practices/resources. response-requested labels Oct 23, 2019
@pcharasala
Copy link
Author

pcharasala commented Oct 23, 2019

Hi @awschristou,

Thank you! Thank you! That works.
The piece I was missing is the fact that environment variable keys must be there at both template.yaml and templates.json.
I have tested with multiple variables too and I am giving it here could be useful to someone else.
In the temlate.yaml..

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandlerN10
      Runtime: nodejs10.x
      Environment:
        Variables:
          SAMPLE1: Default Sample 1 Value
         SAMPLE2: Default Sample2 Value

and in templates.json running configuration as

{
    "templates": {
        "sam-app/template.yaml": {
            "handlers": {
                "app.lambda_handler": {
                    "event": {},
                    "environmentVariables": {"SAMPLE1": "My sample 1 value", "SAMPLE2": "My Sample2"}
                }
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance General information and guidance, answers to FAQs, or recommended best practices/resources. sam
Projects
None yet
Development

No branches or pull requests

3 participants