Repository: aws-cloudformation/cfn-lint

Issue:
Invalid PrimaryKey attribute crashes cfn-lint  instead of raising lint error.
Hi AWS,

I found a minor bug on cfn-lint version: cfn-lint 0.8.3

An attribute in Resource -> Properties-> PrimaryKey leads to crash instead of a raised lint error

Here is a sample template. If  MyInvalidAttr is replaced with a correct attribute eg Name then the template works.
```AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
  sam-app

  Sample SAM Template for sam-app

Globals:
  Function:
    Timeout: 3

Resources:
  MyTable:
    Type: AWS::Serverless::SimpleTable
    Properties:
      TableName: MyTable
      PrimaryKey:
        MyInvalidAttr: id
        Type: String
```
Below is the error:
```
$ cfn-lint -t template.yaml
Traceback (most recent call last):
  File "/Users/emilbryggare/Library/Python/2.7/bin/cfn-lint", line 11, in <module>
    sys.exit(main())
  File "/Users/emilbryggare/Library/Python/2.7/lib/python/site-packages/cfnlint/__main__.py", line 36, in main
    args.regions, args.override_spec))
  File "/Users/emilbryggare/Library/Python/2.7/lib/python/site-packages/cfnlint/core.py", line 46, in run_cli
    return run_checks(filename, template, rules, regions)
  File "/Users/emilbryggare/Library/Python/2.7/lib/python/site-packages/cfnlint/core.py", line 316, in run_checks
    matches.extend(runner.transform())
  File "/Users/emilbryggare/Library/Python/2.7/lib/python/site-packages/cfnlint/__init__.py", line 894, in transform
    matches = transform.transform_template()
  File "/Users/emilbryggare/Library/Python/2.7/lib/python/site-packages/cfnlint/transform.py", line 115, in transform_template
    sam_translator.translate(sam_template=self._template, parameter_values={}))
  File "/Users/emilbryggare/Library/Python/2.7/lib/python/site-packages/samtranslator/translator/translator.py", line 72, in translate
    translated = macro.to_cloudformation(**kwargs)
  File "/Users/emilbryggare/Library/Python/2.7/lib/python/site-packages/samtranslator/model/sam_resources.py", line 537, in to_cloudformation
    dynamodb_resources = self._construct_dynamodb_table()
  File "/Users/emilbryggare/Library/Python/2.7/lib/python/site-packages/samtranslator/model/sam_resources.py", line 546, in _construct_dynamodb_table
    'AttributeName': self.PrimaryKey['Name'],
KeyError: 'Name'
```



Discussion:

Resolving patch:
diff --git a/src/cfnlint/transform.py b/src/cfnlint/transform.py
--- a/src/cfnlint/transform.py
+++ b/src/cfnlint/transform.py
@@ -15,14 +15,14 @@
   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 """
 import os
+import logging
 import six
-
 from samtranslator.parser import parser
 from samtranslator.translator.translator import Translator
 from samtranslator.public.exceptions import InvalidDocumentException
 
 import cfnlint.helpers
-
+LOGGER = logging.getLogger('cfnlint')
 
 class Transform(object):
     """
@@ -119,6 +119,14 @@ def warning(self, message):
                     1, 1,
                     1, 1,
                     self._filename, cfnlint.TransformError(), cause.message))
+        except Exception as e:  # pylint: disable=W0703
+            LOGGER.debug('Error transforming template: %s', str(e))
+            LOGGER.debug('Stack trace: %s', e, exc_info=True)
+            message = 'Error transforming template: {0}'
+            matches.append(cfnlint.Match(
+                1, 1,
+                1, 1,
+                self._filename, cfnlint.TransformError(), message.format(str(e))))
 
         return matches
 


Test patch: