2
votes

The following snippet is from a Cloudformation formation template:

...
LambdaFunctionAssociations:
  - !If
    - ProtectDistribution
    -
      - EventType: viewer-request
        LambdaFunctionARN: !GetAtt LambdaEdgeProtection.Outputs.CheckAuthHandler
      - EventType: origin-response
        LambdaFunctionARN: !GetAtt LambdaEdgeProtection.Outputs.HttpHeadersHandler
    - !Ref AWS::NoValue
...

It's a part of a DefaultCacheBehavior within a DistributionConfig of a CloudFront distribution. It's giving me this error when trying to create the stack:

Property validation failure: [Value of property {/DistributionConfig/DefaultCacheBehavior/LambdaFunctionAssociations/0} does not match type {Object}]

Where am I going wrong please?

1

1 Answers

1
votes

In - !If condition of your code you have already declared the array before the if condition and if the condition gets true, - - EventType: viewer-request here you are again providing array, which is wrong. You should try it this way,

...
LambdaFunctionAssociations:
  - !If
    - ProtectDistribution
    - EventType: viewer-request
      LambdaFunctionARN: !GetAtt LambdaEdgeProtection.Outputs.CheckAuthHandler
    - !Ref AWS::NoValue
  - !If
    - ProtectDistribution
    - EventType: origin-response
      LambdaFunctionARN: !GetAtt LambdaEdgeProtection.Outputs.HttpHeadersHandler
    - !Ref AWS::NoValue 
...