Repository: aws-cloudformation/cfn-lint

Issue:
E0002 bug when using parameters for DynamoDB AttributeDefinitions
*cfn-lint version: 0.28.2*

*Description of issue.*

Rule E3039 (added in 0.28.0) doesn't support Refs and results in a E0002 error for the template. 

Repeatable with this template snippet:

```
AWSTemplateFormatVersion: '2010-09-09'

Parameters:
    HashKeyName:
        Description: Primary Key Name
        Type: String
        AllowedPattern: '[a-zA-Z0-9]*'
        MinLength: '1'
        MaxLength: '2048'
        ConstraintDescription: must contain only alphanumberic characters

    HashKeyType:
        Description: Primary Key Type
        Type: String
        Default: S
        AllowedPattern: '[S|N]'
        MinLength: '1'
        MaxLength: '1'
        ConstraintDescription: must be either S or N

    RangeKeyName:
        Description: Sort Key Name
        Type: String
        Default: 'NA'
        AllowedPattern: '[a-zA-Z0-9]*'
        MinLength: '0'
        MaxLength: '2048'
        ConstraintDescription: must contain only alphanumberic characters

    RangeKeyType:
        Description: Sort Key Type
        Type: String
        Default: S
        AllowedPattern: '[S|N]'
        MinLength: '0'
        MaxLength: '1'
        ConstraintDescription: must be either S or Ns

Conditions:
    isRangeKeyAvailable: !Not [ !Equals [ !Ref RangeKeyName, 'NA' ] ]

Resources:
    DynamoDBTable:
        DeletionPolicy: Delete
        UpdateReplacePolicy: Delete
        Type: AWS::DynamoDB::Table
        Properties:
            AttributeDefinitions: !If
                - isRangeKeyAvailable
                - - AttributeName: !Ref HashKeyName
                    AttributeType: !Ref HashKeyType
                  - AttributeName: !Ref RangeKeyName
                    AttributeType: !Ref RangeKeyType
                - - AttributeName: !Ref HashKeyName
                    AttributeType: !Ref HashKeyType
            KeySchema: !If
                - isRangeKeyAvailable
                - - AttributeName: !Ref HashKeyName
                    KeyType: HASH
                  - AttributeName: !Ref RangeKeyName
                    KeyType: RANGE
                - - AttributeName: !Ref HashKeyName
                    KeyType: HASH
```



Discussion:

Resolving patch:
diff --git a/src/cfnlint/rules/resources/dynamodb/AttributeMismatch.py b/src/cfnlint/rules/resources/dynamodb/AttributeMismatch.py
--- a/src/cfnlint/rules/resources/dynamodb/AttributeMismatch.py
+++ b/src/cfnlint/rules/resources/dynamodb/AttributeMismatch.py
@@ -77,7 +77,8 @@ def check_property_set(self, property_set, path):
             message = 'The set of Attributes in AttributeDefinitions: {0} and KeySchemas: {1} must match at {2}'
             matches.append(RuleMatch(
                 path,
-                message.format(sorted(list(attributes)), sorted(list(keys)), '/'.join(map(str, path)))
+                message.format(sorted(list(attributes)), sorted(
+                    list(keys)), '/'.join(map(str, path)))
             ))
 
         return matches
@@ -86,7 +87,8 @@ def check(self, properties, path, cfn):
         """Check itself"""
         matches = []
 
-        property_sets = cfn.get_object_without_conditions(properties, path)
+        property_sets = cfn.get_object_without_conditions(
+            properties, ['AttributeDefinitions', 'KeySchema', 'GlobalSecondaryIndexes', 'LocalSecondaryIndexes'])
         for property_set in property_sets:
             matches.extend(self.check_property_set(property_set, path))
         return matches


Test patch: