简体   繁体   中英

Property validation failure in Cloudformation

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?

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 
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM