Skip to content

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

Closed

Description

@studds

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

Activity

  1. sanathkr commented on Jun 29, 2018

    @sanathkr

    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?

  2. studds commented on Jul 11, 2018

    @studds
    Author

    Yes, this will work in my case.

  3. jfuss commented on Jun 15, 2019

    @jfuss
    Contributor

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

    Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions