Skip to content

Default parameter value of Empty String is not recognized in processing of Intrinsic function #1476

@michaelj-smith

Description

@michaelj-smith

Description

First off, thank you so much for the support of Intrinsic Functions provided in #1261 ! This is really excellent work!

I've found a minor bug in the processing of Intrinsics when referencing a parameter with a default value of the empty string (""). Instead of interpolating the empty string, the intrinsic processesor interpolates the name of the parameter.

Steps to reproduce

Sample SAM YML template in ./test.sam.yml:
NOTE: the "paramFeatureBranch" parameter has a default value of ""

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
  paramEnvironment:
    Type: String
    Description: Which environment do you want to deploy to? (local,dev,stage, or prod)
    AllowedValues:
    - local
    - dev
    - stage
    - prod
    Default: local
  paramFeatureBranch:
    Type: String
    Description: Provide the name of the feature branch if this in not a build from the master code branch.
    Default: ""

Globals:
  Function:
    Runtime: nodejs10.x
    MemorySize: 512
    Timeout: 30
    Environment:
      Variables:
        dbTableName: !Sub "${paramEnvironment}${paramFeatureBranch}_Products"

Resources:
  resLambdaTest:
    Type: AWS::Serverless::Function
    Properties:
      Handler: test.handler
      FunctionName: !Sub "${paramEnvironment}${paramFeatureBranch}_test"
      CodeUri: src
      Events:
        api:
          Type: Api
          Properties:
            Path: /test
            Method: GET

And this sample handler file in src/test.js:

exports.handler = async () => {
  const response = {
    dbTableName: process.env.dbTableName
  };

  return {
    statusCode: 200,
    body: JSON.stringify(response)
  };
};

Execute the local api via this command:

sam local start-api --template test.sam.yml

Execute a curl/browser/Postman request to http://127.0.0.1:3000/test

Observed result

API response is:

{
    "dbTableName": "localparamFeatureBranch_Products"
}

Where ${paramFeatureBranch} was interpolated as "paramFeatureBranch"

Expected result

{
    "dbTableName": "local_Products"
}

where ${paramFeatureBranch} should have been interpolated as ""

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

  1. OS: macOS v10.14.6 (Mojave)
  2. sam --version: SAM CLI, version 0.22.0

I also tried executing the local api using parameter-overrides with this command:

sam local start-api --template test.sam.yml --parameter-overrides "ParameterKey=paramFeatureBranch,ParameterValue=" 

but that fails with this error message:

Error: Invalid value for "--parameter-overrides": ParameterKey=paramFeatureBranch,ParameterValue= is not in valid format. It must look something like 'ParameterKey=KeyPairName,ParameterValue=MyKey ParameterKey=InstanceType,ParameterValue=t1.micro'

This is fine, I understand that passing in an empty string for parameter overrides may not be supported. However, I expect that a default value of empty string should be recognized.

Thanks for your support!

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