Skip to content

Commit 8804733

Browse files
53ningenjlhood
authored andcommitted
fix: make sure Name and Type exists as a property of PrimaryKey of SimpleTable (#1054)
1 parent 8c0c0a0 commit 8804733

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-0
lines changed

samtranslator/model/sam_resources.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ def _construct_dynamodb_table(self):
537537
dynamodb_table = DynamoDBTable(self.logical_id, depends_on=self.depends_on, attributes=self.resource_attributes)
538538

539539
if self.PrimaryKey:
540+
if 'Name' not in self.PrimaryKey or 'Type' not in self.PrimaryKey:
541+
raise InvalidResourceException(
542+
self.logical_id,
543+
'\'PrimaryKey\' is missing required Property \'Name\' or \'Type\'.'
544+
)
540545
primary_key = {
541546
'AttributeName': self.PrimaryKey['Name'],
542547
'AttributeType': self._convert_attribute_type(self.PrimaryKey['Type'])
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Resources:
2+
Table:
3+
Type: AWS::Serverless::SimpleTable
4+
Properties:
5+
PrimaryKey:
6+
Id: id
7+
Type: String
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Resources:
2+
Table:
3+
Type: AWS::Serverless::SimpleTable
4+
Properties:
5+
PrimaryKey:
6+
Name: id
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"errors": [
3+
{
4+
"errorMessage": "Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'."
5+
}
6+
],
7+
"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'."
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"errors": [
3+
{
4+
"errorMessage": "Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'."
5+
}
6+
],
7+
"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'."
8+
}

tests/translator/test_translator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw
457457
'error_multiple_resource_errors',
458458
'error_s3_not_in_template',
459459
'error_table_invalid_attributetype',
460+
'error_table_primary_key_missing_name',
461+
'error_table_primary_key_missing_type',
460462
'error_invalid_resource_parameters',
461463
'error_reserved_sam_tag',
462464
'existing_event_logical_id',

0 commit comments

Comments
 (0)