diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 8bf97994d0..dfacebbecc 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -537,6 +537,11 @@ def _construct_dynamodb_table(self): dynamodb_table = DynamoDBTable(self.logical_id, depends_on=self.depends_on, attributes=self.resource_attributes) if self.PrimaryKey: + if 'Name' not in self.PrimaryKey or 'Type' not in self.PrimaryKey: + raise InvalidResourceException( + self.logical_id, + '\'PrimaryKey\' is missing required Property \'Name\' or \'Type\'.' + ) primary_key = { 'AttributeName': self.PrimaryKey['Name'], 'AttributeType': self._convert_attribute_type(self.PrimaryKey['Type']) diff --git a/tests/translator/input/error_table_primary_key_missing_name.yaml b/tests/translator/input/error_table_primary_key_missing_name.yaml new file mode 100644 index 0000000000..af257bc02f --- /dev/null +++ b/tests/translator/input/error_table_primary_key_missing_name.yaml @@ -0,0 +1,7 @@ +Resources: + Table: + Type: AWS::Serverless::SimpleTable + Properties: + PrimaryKey: + Id: id + Type: String diff --git a/tests/translator/input/error_table_primary_key_missing_type.yaml b/tests/translator/input/error_table_primary_key_missing_type.yaml new file mode 100644 index 0000000000..3ff377e3b4 --- /dev/null +++ b/tests/translator/input/error_table_primary_key_missing_type.yaml @@ -0,0 +1,6 @@ +Resources: + Table: + Type: AWS::Serverless::SimpleTable + Properties: + PrimaryKey: + Name: id diff --git a/tests/translator/output/error_table_primary_key_missing_name.json b/tests/translator/output/error_table_primary_key_missing_name.json new file mode 100644 index 0000000000..de5a712c21 --- /dev/null +++ b/tests/translator/output/error_table_primary_key_missing_name.json @@ -0,0 +1,8 @@ +{ + "errors": [ + { + "errorMessage": "Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'." + } + ], + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'." +} \ No newline at end of file diff --git a/tests/translator/output/error_table_primary_key_missing_type.json b/tests/translator/output/error_table_primary_key_missing_type.json new file mode 100644 index 0000000000..de5a712c21 --- /dev/null +++ b/tests/translator/output/error_table_primary_key_missing_type.json @@ -0,0 +1,8 @@ +{ + "errors": [ + { + "errorMessage": "Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'." + } + ], + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'." +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index bc8a90f6f7..957748715f 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -457,6 +457,8 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw 'error_multiple_resource_errors', 'error_s3_not_in_template', 'error_table_invalid_attributetype', + 'error_table_primary_key_missing_name', + 'error_table_primary_key_missing_type', 'error_invalid_resource_parameters', 'error_reserved_sam_tag', 'existing_event_logical_id',