CloudFormation Optional Map Property - DeadLetterQueue

Viewed 64

I need DeadLetterQueue property in 'AWS::Serverless::Function' to be created only if Env=ppd or Env=prod

Conditions:
  IsPpdOrPrdEnv: !Or [!Equals [!Ref "Env", ppd], !Equals [!Ref "Env", prod]]
<...>
Resources:
  <...>
  TestFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      FunctionName: !Sub '${Env}-Test-Function'
      DeadLetterQueue: 
        TargetArn: !If [IsPpdOrPrdEnv, !Ref TestSNSTopic, !Ref "AWS::NoValue"]
        Type: !If [IsPpdOrPrdEnv, SNS, !Ref "AWS::NoValue"]
  <...>

The error:

Transform AWS::Serverless-2016-10-31 failed with: Internal transform failure.

I also tried:

     DeadLetterQueue: 
        !If
          - IsPpdOrPrdEnv
          - 
            TargetArn: !Ref TestSNSTopic
            Type: SNS
          - !Ref "AWS::NoValue"

The error:

Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TestFunction] is invalid. 'DeadLetterQueue' requires Type and TargetArn properties to be specified.

Any advise, please?

1 Answers

This seems to be bug/limitation of the SAM. There are open issues (here and here) in github which describe what you are experiencing.

Since both issues are open, they are not resolved. The only workaround provided is:

We ended up needing to add a (manual or scripted) pre-deploy step that just removes the entire [DeadLetterQueue] config part if a [DeadLetterQueue] isn't desired.

Related