Cfn-python-lint: Setting `AutoPublishAlias` value to a Ref reports E1019 violation on a different Property

Created on 4 Jun 2019  路  2Comments  路  Source: aws-cloudformation/cfn-python-lint

*cfn-lint version: 0.21.4

Setting AutoPublishAlias value to a Ref, causes E1019 to be reported on a
different property that also uses that Ref as a part of Sub. This appears to be new to 0.21.4
as it is not present on 0.21.3; perhaps related to #582 and result of
d57c041181f761f98fe2e86fff4f709dd037db15 ?

Failing Example on 0.21.4 (note that FunctionName property is reported):

$ cat template.yaml
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
  EnvironmentName:
    Description: Environment where the function resides.
    Type: String
    Default: dev

Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub func-${EnvironmentName}-${AWS::Region}
      AutoPublishAlias: !Ref EnvironmentName
      Handler: lambda_function.handler
      Runtime: python3.6
      CodeUri:
        Bucket: foo
        Key: func.zip

$ docker run -it \
    -v $(pwd):/var/tmp/ \
    python:3.7.1-alpine3.8 \
    /bin/sh \
    -c "pip install -q 'cfn-lint==0.21.4' && cfn-lint -v && cfn-lint -t /var/tmp/template.yaml"
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
cfn-lint 0.21.4
E1019 Parameter EnvironmentName for Fn::Sub not found at Resources/Function/Properties/FunctionName/Fn::Sub
/var/tmp/template.yaml:11:3

$

No issue if a string value for AutoPublishAlias is used instead of a Ref:

$ cat template-string-alias.yaml
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
  EnvironmentName:
    Description: Environment where the function resides.
    Type: String
    Default: dev

Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub func-${EnvironmentName}-${AWS::Region}
      AutoPublishAlias: myalias
      Handler: lambda_function.handler
      Runtime: python3.6
      CodeUri:
        Bucket: foo
        Key: func.zip

$ docker run -it \
    -v $(pwd):/var/tmp/ \
    python:3.7.1-alpine3.8 \
    /bin/sh \
    -c "pip install -q 'cfn-lint==0.21.4' && cfn-lint -v && cfn-lint -t /var/tmp/template-string-alias.yaml"
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
cfn-lint 0.21.4

$

Using a Ref for AutoPublishAlias does not report the error on 0.21.3. Our
use does include a default value for the Parameter which may be relevant to not
seeing the issue described in #582.

$ cat template.yaml
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
  EnvironmentName:
    Description: Environment where the function resides.
    Type: String
    Default: dev

Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub func-${EnvironmentName}-${AWS::Region}
      AutoPublishAlias: !Ref EnvironmentName
      Handler: lambda_function.handler
      Runtime: python3.6
      CodeUri:
        Bucket: foo
        Key: func.zip

$ docker run -it \
    -v $(pwd):/var/tmp/ \
    python:3.7.1-alpine3.8 \
    /bin/sh \
    -c "pip install -q 'cfn-lint==0.21.3' && cfn-lint -v && cfn-lint -t /var/tmp/template.yaml"
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
cfn-lint 0.21.3

$
bug

Most helpful comment

Yea, sorry about that. I should have a fix in early next week with a release to get this fixed for you.

All 2 comments

I'm seeing the same issue. Setting the AutoPublishAlias with a !Ref throws an E1019 for every usage of !Sub that uses the referenced parameter.

An E1012 is also being thrown on the serverless function itself.

Seems to happen regardless of whether or not the referenced parameter has a default value set.

Yea, sorry about that. I should have a fix in early next week with a release to get this fixed for you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthelgen picture matthelgen  路  4Comments

AlessandroLorenzi picture AlessandroLorenzi  路  3Comments

KarthickEmis picture KarthickEmis  路  4Comments

Satak picture Satak  路  4Comments

mikecee picture mikecee  路  4Comments