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

start-api: Intrinsics like AWS::StackName appear undefined #490

Closed
studds opened this issue Jun 18, 2018 · 3 comments
Closed

start-api: Intrinsics like AWS::StackName appear undefined #490

studds opened this issue Jun 18, 2018 · 3 comments

Comments

@studds
Copy link

studds commented Jun 18, 2018

Description:

In v0.2.11 when running with sam local start-api, !Ref AWS::StackName returned 'goformation-stack' - I believe defined in https://github.com/awslabs/aws-sam-cli/blob/release/v0.2.11/vendor/github.com/awslabs/goformation/intrinsics/ref.go. In v0.3.0, it seems like nothing is returned.

Are these intrinsics still present in v0.3.0?

Steps to reproduce the issue:

  1. Create a template that references AWS::StackName (see template.yaml below)
  2. Create a app.js (see below) which logs process.env.STACK_NAME
  3. Run sam local start-api
  4. Navigate to http://localhost:3000/hello

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
    sam-app

    Sample SAM Template for sam-app
    
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
    Function:
        Timeout: 3


Resources:

    HelloWorldFunction:
        Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
        Properties:
            Handler: app.lambda_handler
            Runtime: nodejs8.10
            Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
                Variables:
                    STACK_NAME: !Ref AWS::StackName
            Events:
                HelloWorld:
                    Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
                    Properties:
                        Path: /hello
                        Method: get

app.js

exports.lambda_handler = async (event, context, callback) => {
	console.log('stack name: ' + process.env.STACK_NAME);
    callback(null, {
        'statusCode': 200,
        'body': 'OK'
    });
};

Observed result:

v0.2.11: log contains stack name: goformation-stack
v0.3.0: log contains stack name:

Expected result:

Both versions should output a stack name.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

Output of sam --version:

SAM CLI, version 0.3.0

Optional Debug logs:

Add --debug flag to command you are running

@sanathkr
Copy link
Contributor

Yes, this is a breaking change between the two versions. After v0.3.0 we stopped faking default AWS parameter values. Instead you can directly override the environment variable by passing value to sam local start-api --env-vars command.

Would this work for you?

@studds
Copy link
Author

studds commented Jul 11, 2018

Yes, this will work in my case.

@jfuss
Copy link
Contributor

jfuss commented Jun 15, 2019

We started resolving AWS::StackName in v0.6.1. Locally the StackName is defined as 'local'.

Closing

@jfuss jfuss closed this as completed Jun 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants