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

Unknown exception while processing rule WS1004: expected string or bytes-like object #62

Closed
t2b opened this issue Jun 14, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@t2b
Copy link

t2b commented Jun 14, 2021

The cfn-lint rule WS1004 raises an exception if the property LogGroupName of an AWS::Logs::LogGroup is a Sub function with a variable map.

Expected Behavior

The rule WS1004 should analyze LogGroupName properties without errors and match correct configured LogGroups to the lambda functions.

Current Behavior

Rule WS1004 raises an exception:
TypeError: expected string or bytes-like object

Steps to Reproduce (for bugs)

template.yml

Transform: AWS::Serverless-2016-10-31

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.8
      Handler: index.handler
      MemorySize: 128
      Timeout: 3
      Tracing: Active

  CodePipelineNotificationLogGroup:
    Type: AWS::Logs::LogGroup
    UpdateReplacePolicy: Delete
    DeletionPolicy: Delete
    Properties:
      LogGroupName: !Sub
        - "/aws/lambda/${FunctionName}"
        - FunctionName: !Ref MyFunction
      RetentionInDays: 400
cfn-lint -a cfn_lint_serverless.rules -t template.yml

Environment

  • cfn-lint==0.49.2
  • cfn-lint-serverless==0.1.8

paste logs here

E0002 Unknown exception while processing rule WS1004: expected string or bytes-like object
template.yml:1:1
@t2b t2b added the bug Something isn't working label Jun 14, 2021
@nmoutschen
Copy link
Contributor

Hi @t2b !

Thanks for reporting this. I can confirm the bug and will push out a fix soon in version 0.1.9.

I'm also adding two new test cases to catch this:

Ref in a Sub:

AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"

Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Runtime: python3.8
      Handler: main.handler
      Tracing: Active

  LogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Sub
        - "/aws/lambda/${Fn}"
        - Fn: !Ref Function

      RetentionInDays: 7

Hard coded value in a Sub:

AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"

Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: my-function-name
      CodeUri: .
      Runtime: python3.8
      Handler: main.handler
      Tracing: Active

  LogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Sub
        - "/aws/lambda/${Fn}"
        - Fn: my-function-name

      RetentionInDays: 7

@nmoutschen
Copy link
Contributor

And there we go: version 0.1.9 is out with the bug fix. 😄 Thanks again for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants