Skip to content

Environment variables ignored/don't get set with referenced Parameters default values. #450

Closed

Description

@tebruno99

When sam local 3.0 runs my template that has !Ref as values to Parameters for ENV variables, the default value is not used if the ENV variable is not set by the shell. I believe this worked previously because all my templates are setup this way and I was using sam local before the 3.0 update. Although I cannot confirm at this time.

Transform: AWS::Serverless-2016-10-31

Parameters:
  ENV:
    Type: String
    Default: "dev"
    Description: Target Environment

Description: My Test Project
Resources:
  SomeCode:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: go1.x
      Handler: main
      CodeUri: ./
      Environment:
        Variables:
          DEPLOY_ENV: !Ref ENV
      Events:
        MyCode:
          Type: Api
          Properties:
            Path: /gettest
            Method: GET

Result on sam local start-api & request:

2018/05/31 19:43:39 ENV: [AWS_DEFAULT_REGION] = us-west-2
2018/05/31 19:43:39 ENV: [DEPLOY_ENV] = 

I would expect the !Ref to resolve to the Parameter default value, and then later be overridden by the ENV variable. As if sam local deployed the template the same way Cloudformation builds the lambda/stack

Activity

  1. sanathkr commented on Jun 1, 2018

    @sanathkr

    This is a regression. We will get it fixed

  2. bnegrao commented on Jun 12, 2018

    @bnegrao

    I am having that problem too.

  3. sbates commented on Jul 3, 2018

    @sbates

    We would very much like to use something newer than 0.2.0 (we stayed there because of all the .3 breaking changes), but we make heavy use of !Sub and !Ref with parameters in our sam file. I don't see a good reason to trade up to .4 until we don't have to make heavy hardcoding changes to a local yaml file. It would be really nice if we had one sam.yaml to rule them all really.

  4. MRODG commented on Aug 17, 2018

    @MRODG

    Hi do you know how parse this parameter for sam deploy commad?
    I tried this:

    sam deploy --template-file ./serverless-output.yaml --stack-name TextFileGenStack --capabilities CAPABILITY_IAM --TargetEnv dev2

    TargetEnv is the Parameter that would take in my target environment from command but I am getting this error:

    usage: aws [options] [ ...] [parameters]
    To see help text, you can run:

    aws help
    aws help
    aws help
    aws: error: argument subcommand: Invalid choice, valid choices are:

    push | register
    deregister | install
    uninstall

  5. jfuss commented on Aug 17, 2018

    @jfuss
    Contributor

    @MRODG This is not related to this issue at all. --TargetEnv is not a valid option. You can find docs here but you should use the --parameter-overrides option for what you are trying to do.

    Also in the future, please use other support channels for questions like this, such as our slack channel (#samdev) or stackoverflow. Github is for bugs and feature requests.

  6. RohitRox commented on Oct 3, 2018

    @RohitRox

    I am waiting for the fix too

  7. jfuss commented on Oct 3, 2018

    @jfuss
    Contributor

    This was addressed in #657 but is waiting for a release.

    Updating labels to reflect current state.

  8. added
    stage/waiting-for-release
    on Oct 3, 2018
  9. jfuss commented on Oct 24, 2018

    @jfuss
    Contributor

    Closing. Was released with 0.6.1

  10. added a commit that references this issue on May 19, 2023
  11. added a commit that references this issue on May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/1-criticalstage/waiting-for-releasetype/regression

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions