Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Resources:
Table:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Id: id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type: String
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Resources:
Table:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: id
Original file line number Diff line number Diff line change
@@ -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'."
}
Original file line number Diff line number Diff line change
@@ -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'."
}
2 changes: 2 additions & 0 deletions tests/translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down