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

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

Closed
tebruno99 opened this issue May 31, 2018 · 8 comments
Labels
priority/1-critical stage/waiting-for-release Fix has been merged to develop and is waiting for a release type/regression

Comments

@tebruno99
Copy link

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

@sanathkr
Copy link
Contributor

sanathkr commented Jun 1, 2018

This is a regression. We will get it fixed

@bnegrao
Copy link

bnegrao commented Jun 12, 2018

I am having that problem too.

@sbates
Copy link

sbates commented Jul 3, 2018

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.

@MRODG
Copy link

MRODG commented Aug 17, 2018

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

@jfuss
Copy link
Contributor

jfuss commented Aug 17, 2018

@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.

@RohitRox
Copy link

RohitRox commented Oct 3, 2018

I am waiting for the fix too

@jfuss
Copy link
Contributor

jfuss commented Oct 3, 2018

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

Updating labels to reflect current state.

@jfuss jfuss added the stage/waiting-for-release Fix has been merged to develop and is waiting for a release label Oct 3, 2018
@jfuss
Copy link
Contributor

jfuss commented Oct 24, 2018

Closing. Was released with 0.6.1

@jfuss jfuss closed this as completed Oct 24, 2018
mndeveci added a commit to mndeveci/aws-sam-cli that referenced this issue May 19, 2023
* Onboarded ruby3.2

* Re-order runtimes in test_cli.

* Remove deprecated Python3.6

* Add ruby3.2 to build.yml.

* Update build.yml

* Update build.yml to run Ruby3.2.

* temp: use private lambda builders

* temp: use private lambda builders

* try

* try use GH_TOKEN to access private repo

* try use GH_TOKEN to access private repo

* try use GH_TOKEN to access private repo

* Revert "try use GH_TOKEN to access private repo"

This reverts commit eadf4ea650985a4b4fabe5ff82b73eac01dc7c32.

* Revert "try use GH_TOKEN to access private repo"

This reverts commit a32b86c51ce162ca0680b303dcd889bd65385214.

* Revert "try use GH_TOKEN to access private repo"

This reverts commit 52ff9084d0c723ce3970ec60ad233343c3fe3157.

* Revert "try"

This reverts commit 5fc353914e2c126b4a04e2a3b6040356a91787dc.

* Revert "temp: use private lambda builders"

This reverts commit e39d06f6dc5e0a4ffeee1a2357eafd9b2672d118.

---------

Co-authored-by: trivenay <trivenay@amazon.com>
Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
Co-authored-by: Sean O Brien <briensea@amazon.com>
moelasmar added a commit that referenced this issue May 26, 2023
* Onboarded ruby3.2

* Re-order runtimes in test_cli.

* Remove deprecated Python3.6

* Add ruby3.2 to build.yml.

* Update build.yml

* Update build.yml to run Ruby3.2.

* temp: use private lambda builders

* temp: use private lambda builders

* try

* try use GH_TOKEN to access private repo

* try use GH_TOKEN to access private repo

* try use GH_TOKEN to access private repo

* Revert "try use GH_TOKEN to access private repo"

This reverts commit eadf4ea650985a4b4fabe5ff82b73eac01dc7c32.

* Revert "try use GH_TOKEN to access private repo"

This reverts commit a32b86c51ce162ca0680b303dcd889bd65385214.

* Revert "try use GH_TOKEN to access private repo"

This reverts commit 52ff9084d0c723ce3970ec60ad233343c3fe3157.

* Revert "try"

This reverts commit 5fc353914e2c126b4a04e2a3b6040356a91787dc.

* Revert "temp: use private lambda builders"

This reverts commit e39d06f6dc5e0a4ffeee1a2357eafd9b2672d118.

---------

Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>
Co-authored-by: trivenay <trivenay@amazon.com>
Co-authored-by: Sean O Brien <briensea@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/1-critical stage/waiting-for-release Fix has been merged to develop and is waiting for a release type/regression
Projects
None yet
Development

No branches or pull requests

7 participants