Skip to content

Commit 886dcdc

Browse files
oharaandrew314jfuss
authored andcommitted
feat: Add SSE to SimpleTable
1 parent 748a9e9 commit 886dcdc

23 files changed

+261
-24
lines changed

docs/cloudformation_compatibility.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ DynamoDB
103103
Stream All
104104
StartingPosition All
105105
BatchSize All
106+
SSESpecification All
106107
======================== ================================== ========================
107108

108109
Api

docs/globals.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ presently.
8080
BinaryMediaTypes:
8181
Cors:
8282
83+
SimpleTable:
84+
SSESpecification
85+
8386
Implicit APIs
8487
~~~~~~~~~~~~~
8588

samtranslator/model/dynamodb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class DynamoDBTable(Resource):
1313
'ProvisionedThroughput': PropertyType(True, dict_of(is_str(), one_of(is_type(int), is_type(dict)))),
1414
'StreamSpecification': PropertyType(False, is_type(dict)),
1515
'TableName': PropertyType(False, one_of(is_str(), is_type(dict))),
16-
'Tags': PropertyType(False, list_of(is_type(dict)))
17-
}
16+
'Tags': PropertyType(False, list_of(is_type(dict))),
17+
'SSESpecification': PropertyType(False, is_type(dict))
18+
}
1819

1920
runtime_attrs = {
2021
"name": lambda self: ref(self.logical_id),

samtranslator/model/sam_resources.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
""" SAM macro definitions """
2-
from copy import deepcopy
3-
42
from six import string_types
53
from tags.resource_tagging import get_tag_list
64
import samtranslator.model.eventsources
@@ -56,7 +54,8 @@ class SamFunction(SamResourceMacro):
5654
'AutoPublishAlias': PropertyType(False, one_of(is_str()))
5755
}
5856
event_resolver = ResourceTypeResolver(samtranslator.model.eventsources, samtranslator.model.eventsources.pull,
59-
samtranslator.model.eventsources.push, samtranslator.model.eventsources.cloudwatchlogs)
57+
samtranslator.model.eventsources.push,
58+
samtranslator.model.eventsources.cloudwatchlogs)
6059

6160
# DeadLetterQueue
6261
dead_letter_queue_policy_actions = {'SQS': 'sqs:SendMessage', 'SNS': 'sns:Publish'}
@@ -67,7 +66,6 @@ class SamFunction(SamResourceMacro):
6766
"Version": LambdaVersion.resource_type,
6867
}
6968

70-
7169
def resources_to_link(self, resources):
7270
try:
7371
return {
@@ -148,7 +146,6 @@ def _get_resolved_alias_name(self, property_name, original_alias_value, intrinsi
148146

149147
return resolved_alias_name
150148

151-
152149
def _construct_lambda_function(self):
153150
"""Constructs and returns the Lambda function.
154151
@@ -216,7 +213,9 @@ def _construct_role(self, managed_policy_map):
216213
policy_documents = []
217214

218215
if self.DeadLetterQueue:
219-
policy_documents.append(IAMRolePolicies.dead_letter_queue_policy(self.dead_letter_queue_policy_actions[self.DeadLetterQueue['Type']], self.DeadLetterQueue['TargetArn']))
216+
policy_documents.append(IAMRolePolicies.dead_letter_queue_policy(
217+
self.dead_letter_queue_policy_actions[self.DeadLetterQueue['Type']],
218+
self.DeadLetterQueue['TargetArn']))
220219

221220
for index, policy_entry in enumerate(function_policies.get()):
222221

@@ -247,8 +246,9 @@ def _construct_role(self, managed_policy_map):
247246
managed_policy_arns.append(policy_arn)
248247
else:
249248
# Policy Templates are not supported here in the "core"
250-
raise InvalidResourceException(self.logical_id,
251-
"Policy at index {} in the 'Policies' property is not valid".format(index))
249+
raise InvalidResourceException(
250+
self.logical_id,
251+
"Policy at index {} in the 'Policies' property is not valid".format(index))
252252

253253
execution_role.ManagedPolicyArns = list(managed_policy_arns)
254254
execution_role.Policies = policy_documents or None
@@ -420,7 +420,8 @@ def _construct_alias(self, name, function, version):
420420
def _validate_deployment_preference_and_add_update_policy(self, deployment_preference_collection, lambda_alias,
421421
intrinsics_resolver):
422422
if 'Enabled' in self.DeploymentPreference:
423-
self.DeploymentPreference['Enabled'] = intrinsics_resolver.resolve_parameter_refs(self.DeploymentPreference['Enabled'])
423+
self.DeploymentPreference['Enabled'] = intrinsics_resolver.resolve_parameter_refs(
424+
self.DeploymentPreference['Enabled'])
424425
if isinstance(self.DeploymentPreference['Enabled'], dict):
425426
raise InvalidResourceException(self.logical_id, "'Enabled' must be a boolean value")
426427

@@ -431,8 +432,9 @@ def _validate_deployment_preference_and_add_update_policy(self, deployment_prefe
431432

432433
if deployment_preference_collection.get(self.logical_id).enabled:
433434
if self.AutoPublishAlias is None:
434-
raise InvalidResourceException(self.logical_id,
435-
"'DeploymentPreference' requires AutoPublishAlias property to be specified")
435+
raise InvalidResourceException(
436+
self.logical_id,
437+
"'DeploymentPreference' requires AutoPublishAlias property to be specified")
436438
if lambda_alias is None:
437439
raise ValueError('lambda_alias expected for updating it with the appropriate update policy')
438440

@@ -510,7 +512,8 @@ class SamSimpleTable(SamResourceMacro):
510512
'PrimaryKey': PropertyType(False, dict_of(is_str(), is_str())),
511513
'ProvisionedThroughput': PropertyType(False, dict_of(is_str(), one_of(is_type(int), is_type(dict)))),
512514
'TableName': PropertyType(False, one_of(is_str(), is_type(dict))),
513-
'Tags': PropertyType(False, is_type(dict))
515+
'Tags': PropertyType(False, is_type(dict)),
516+
'SSESpecification': PropertyType(False, is_type(dict))
514517
}
515518
attribute_type_conversions = {
516519
'String': 'S',
@@ -523,7 +526,6 @@ def to_cloudformation(self, **kwargs):
523526

524527
return [dynamodb_resources]
525528

526-
527529
def _construct_dynamodb_table(self):
528530
dynamodb_table = DynamoDBTable(self.logical_id, depends_on=self.depends_on)
529531

@@ -549,6 +551,9 @@ def _construct_dynamodb_table(self):
549551

550552
dynamodb_table.ProvisionedThroughput = provisioned_throughput
551553

554+
if self.SSESpecification:
555+
dynamodb_table.SSESpecification = self.SSESpecification
556+
552557
if self.TableName:
553558
dynamodb_table.TableName = self.TableName
554559

samtranslator/plugins/globals/globals.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from samtranslator.public.sdk.resource import SamResourceType
22
from samtranslator.public.intrinsics import is_intrinsics
33

4+
45
class Globals(object):
56
"""
67
Class to parse and process Globals section in SAM template. If a property is specified at Global section for
@@ -44,6 +45,10 @@ class Globals(object):
4445
"MethodSettings",
4546
"BinaryMediaTypes",
4647
"Cors"
48+
],
49+
50+
SamResourceType.SimpleTable.value: [
51+
"SSESpecification"
4752
]
4853
}
4954

@@ -125,7 +130,6 @@ def _parse(self, globals_dict):
125130
"Must be one of the following values - {supported}"
126131
.format(key=key, section=section_name, supported=supported))
127132

128-
129133
# Store all Global properties in a map with key being the AWS::Serverless::* resource type
130134
globals[resource_type] = GlobalProperties(properties)
131135

@@ -135,8 +139,6 @@ def _make_resource_type(self, key):
135139
return self._RESOURCE_PREFIX + key
136140

137141

138-
139-
140142
class GlobalProperties(object):
141143
"""
142144
Object holding the global properties of given type. It also contains methods to perform a merge between
@@ -298,7 +300,6 @@ def _do_merge(self, global_value, local_value):
298300
raise TypeError(
299301
"Unsupported type of objects. GlobalType={}, LocalType={}".format(token_global, token_local))
300302

301-
302303
def _merge_lists(self, global_list, local_list):
303304
"""
304305
Merges the global list with the local list. List merging is simply a concatenation = global + local
@@ -369,7 +370,6 @@ def _token_of(self, input):
369370
else:
370371
return self.TOKEN.PRIMITIVE
371372

372-
373373
class TOKEN:
374374
"""
375375
Enum of tokens used in the merging
@@ -385,7 +385,7 @@ class InvalidGlobalsSectionException(Exception):
385385
Attributes:
386386
message -- explanation of the error
387387
"""
388-
def __init__(self, logical_id, message):
388+
def __init__(self, logical_id, message):
389389
self._logical_id = logical_id
390390
self._message = message
391391

samtranslator/plugins/globals/globals_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from samtranslator.plugins.globals.globals import Globals, InvalidGlobalsSectionException
77

8+
89
class GlobalsPlugin(BasePlugin):
910
"""
1011
Plugin to process Globals section of a SAM template before the template is translated to CloudFormation.

samtranslator/validator/sam_schema/schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@
641641
},
642642
"ProvisionedThroughput": {
643643
"$ref": "#/definitions/AWS::Serverless::SimpleTable.ProvisionedThroughput"
644+
},
645+
"SSESpecification": {
646+
"$ref": "#/definitions/AWS::Serverless::SimpleTable.SSESpecification"
644647
}
645648
},
646649
"type": "object"
@@ -687,6 +690,18 @@
687690
],
688691
"type": "object"
689692
},
693+
"AWS::Serverless::SimpleTable.SSESpecification": {
694+
"additionalProperties": false,
695+
"properties": {
696+
"SSEEnabled": {
697+
"type": "boolean"
698+
}
699+
},
700+
"required": [
701+
"SSEEnabled"
702+
],
703+
"type": "object"
704+
},
690705
"CloudFormationResource": {
691706
"additionalProperties": true,
692707
"properties": {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Globals:
2+
SimpleTable:
3+
SSESpecification:
4+
SSEEnabled: true
5+
6+
Resources:
7+
MinimalTable:
8+
Type: AWS::Serverless::SimpleTable

tests/translator/input/simple_table_ref_parameter_intrinsic.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ Resources:
66
ReadCapacityUnits:
77
Ref: ReadCapacity
88
WriteCapacityUnits:
9-
Ref: WriteCapacity
9+
Ref: WriteCapacity
10+
SSESpecification:
11+
SSEEnabled:
12+
Ref: EnableSSE
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Resources:
2+
TableWithSSE:
3+
Type: 'AWS::Serverless::SimpleTable'
4+
Properties:
5+
SSESpecification:
6+
SSEEnabled: true

0 commit comments

Comments
 (0)