Skip to content

Commit

Permalink
feat: Add SSE to SimpleTable
Browse files Browse the repository at this point in the history
  • Loading branch information
oharaandrew314 authored and jfuss committed May 22, 2018
1 parent 748a9e9 commit 886dcdc
Show file tree
Hide file tree
Showing 23 changed files with 261 additions and 24 deletions.
1 change: 1 addition & 0 deletions docs/cloudformation_compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ DynamoDB
Stream All
StartingPosition All
BatchSize All
SSESpecification All
======================== ================================== ========================

Api
Expand Down
3 changes: 3 additions & 0 deletions docs/globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ presently.
BinaryMediaTypes:
Cors:
SimpleTable:
SSESpecification
Implicit APIs
~~~~~~~~~~~~~

Expand Down
5 changes: 3 additions & 2 deletions samtranslator/model/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class DynamoDBTable(Resource):
'ProvisionedThroughput': PropertyType(True, dict_of(is_str(), one_of(is_type(int), is_type(dict)))),
'StreamSpecification': PropertyType(False, is_type(dict)),
'TableName': PropertyType(False, one_of(is_str(), is_type(dict))),
'Tags': PropertyType(False, list_of(is_type(dict)))
}
'Tags': PropertyType(False, list_of(is_type(dict))),
'SSESpecification': PropertyType(False, is_type(dict))
}

runtime_attrs = {
"name": lambda self: ref(self.logical_id),
Expand Down
31 changes: 18 additions & 13 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
""" SAM macro definitions """
from copy import deepcopy

from six import string_types
from tags.resource_tagging import get_tag_list
import samtranslator.model.eventsources
Expand Down Expand Up @@ -56,7 +54,8 @@ class SamFunction(SamResourceMacro):
'AutoPublishAlias': PropertyType(False, one_of(is_str()))
}
event_resolver = ResourceTypeResolver(samtranslator.model.eventsources, samtranslator.model.eventsources.pull,
samtranslator.model.eventsources.push, samtranslator.model.eventsources.cloudwatchlogs)
samtranslator.model.eventsources.push,
samtranslator.model.eventsources.cloudwatchlogs)

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


def resources_to_link(self, resources):
try:
return {
Expand Down Expand Up @@ -148,7 +146,6 @@ def _get_resolved_alias_name(self, property_name, original_alias_value, intrinsi

return resolved_alias_name


def _construct_lambda_function(self):
"""Constructs and returns the Lambda function.
Expand Down Expand Up @@ -216,7 +213,9 @@ def _construct_role(self, managed_policy_map):
policy_documents = []

if self.DeadLetterQueue:
policy_documents.append(IAMRolePolicies.dead_letter_queue_policy(self.dead_letter_queue_policy_actions[self.DeadLetterQueue['Type']], self.DeadLetterQueue['TargetArn']))
policy_documents.append(IAMRolePolicies.dead_letter_queue_policy(
self.dead_letter_queue_policy_actions[self.DeadLetterQueue['Type']],
self.DeadLetterQueue['TargetArn']))

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

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

execution_role.ManagedPolicyArns = list(managed_policy_arns)
execution_role.Policies = policy_documents or None
Expand Down Expand Up @@ -420,7 +420,8 @@ def _construct_alias(self, name, function, version):
def _validate_deployment_preference_and_add_update_policy(self, deployment_preference_collection, lambda_alias,
intrinsics_resolver):
if 'Enabled' in self.DeploymentPreference:
self.DeploymentPreference['Enabled'] = intrinsics_resolver.resolve_parameter_refs(self.DeploymentPreference['Enabled'])
self.DeploymentPreference['Enabled'] = intrinsics_resolver.resolve_parameter_refs(
self.DeploymentPreference['Enabled'])
if isinstance(self.DeploymentPreference['Enabled'], dict):
raise InvalidResourceException(self.logical_id, "'Enabled' must be a boolean value")

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

if deployment_preference_collection.get(self.logical_id).enabled:
if self.AutoPublishAlias is None:
raise InvalidResourceException(self.logical_id,
"'DeploymentPreference' requires AutoPublishAlias property to be specified")
raise InvalidResourceException(
self.logical_id,
"'DeploymentPreference' requires AutoPublishAlias property to be specified")
if lambda_alias is None:
raise ValueError('lambda_alias expected for updating it with the appropriate update policy')

Expand Down Expand Up @@ -510,7 +512,8 @@ class SamSimpleTable(SamResourceMacro):
'PrimaryKey': PropertyType(False, dict_of(is_str(), is_str())),
'ProvisionedThroughput': PropertyType(False, dict_of(is_str(), one_of(is_type(int), is_type(dict)))),
'TableName': PropertyType(False, one_of(is_str(), is_type(dict))),
'Tags': PropertyType(False, is_type(dict))
'Tags': PropertyType(False, is_type(dict)),
'SSESpecification': PropertyType(False, is_type(dict))
}
attribute_type_conversions = {
'String': 'S',
Expand All @@ -523,7 +526,6 @@ def to_cloudformation(self, **kwargs):

return [dynamodb_resources]


def _construct_dynamodb_table(self):
dynamodb_table = DynamoDBTable(self.logical_id, depends_on=self.depends_on)

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

dynamodb_table.ProvisionedThroughput = provisioned_throughput

if self.SSESpecification:
dynamodb_table.SSESpecification = self.SSESpecification

if self.TableName:
dynamodb_table.TableName = self.TableName

Expand Down
12 changes: 6 additions & 6 deletions samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from samtranslator.public.sdk.resource import SamResourceType
from samtranslator.public.intrinsics import is_intrinsics


class Globals(object):
"""
Class to parse and process Globals section in SAM template. If a property is specified at Global section for
Expand Down Expand Up @@ -44,6 +45,10 @@ class Globals(object):
"MethodSettings",
"BinaryMediaTypes",
"Cors"
],

SamResourceType.SimpleTable.value: [
"SSESpecification"
]
}

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


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

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




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


def _merge_lists(self, global_list, local_list):
"""
Merges the global list with the local list. List merging is simply a concatenation = global + local
Expand Down Expand Up @@ -369,7 +370,6 @@ def _token_of(self, input):
else:
return self.TOKEN.PRIMITIVE


class TOKEN:
"""
Enum of tokens used in the merging
Expand All @@ -385,7 +385,7 @@ class InvalidGlobalsSectionException(Exception):
Attributes:
message -- explanation of the error
"""
def __init__(self, logical_id, message):
def __init__(self, logical_id, message):
self._logical_id = logical_id
self._message = message

Expand Down
1 change: 1 addition & 0 deletions samtranslator/plugins/globals/globals_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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


class GlobalsPlugin(BasePlugin):
"""
Plugin to process Globals section of a SAM template before the template is translated to CloudFormation.
Expand Down
15 changes: 15 additions & 0 deletions samtranslator/validator/sam_schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@
},
"ProvisionedThroughput": {
"$ref": "#/definitions/AWS::Serverless::SimpleTable.ProvisionedThroughput"
},
"SSESpecification": {
"$ref": "#/definitions/AWS::Serverless::SimpleTable.SSESpecification"
}
},
"type": "object"
Expand Down Expand Up @@ -687,6 +690,18 @@
],
"type": "object"
},
"AWS::Serverless::SimpleTable.SSESpecification": {
"additionalProperties": false,
"properties": {
"SSEEnabled": {
"type": "boolean"
}
},
"required": [
"SSEEnabled"
],
"type": "object"
},
"CloudFormationResource": {
"additionalProperties": true,
"properties": {
Expand Down
8 changes: 8 additions & 0 deletions tests/translator/input/globals_for_simpletable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Globals:
SimpleTable:
SSESpecification:
SSEEnabled: true

Resources:
MinimalTable:
Type: AWS::Serverless::SimpleTable
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ Resources:
ReadCapacityUnits:
Ref: ReadCapacity
WriteCapacityUnits:
Ref: WriteCapacity
Ref: WriteCapacity
SSESpecification:
SSEEnabled:
Ref: EnableSSE
6 changes: 6 additions & 0 deletions tests/translator/input/simpletable_with_sse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Resources:
TableWithSSE:
Type: 'AWS::Serverless::SimpleTable'
Properties:
SSESpecification:
SSEEnabled: true
28 changes: 28 additions & 0 deletions tests/translator/output/aws-cn/globals_for_simpletable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"Resources": {
"MinimalTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"ProvisionedThroughput": {
"WriteCapacityUnits": 5,
"ReadCapacityUnits": 5
},
"SSESpecification": {
"SSEEnabled": true
},
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "id"
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"AttributeType": "S"
}
],
"SSESpecification": {
"SSEEnabled": {
"Ref": "EnableSSE"
}
},
"KeySchema": [
{
"KeyType": "HASH",
Expand Down
28 changes: 28 additions & 0 deletions tests/translator/output/aws-cn/simpletable_with_sse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"Resources": {
"TableWithSSE": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"ProvisionedThroughput": {
"WriteCapacityUnits": 5,
"ReadCapacityUnits": 5
},
"SSESpecification": {
"SSEEnabled": true
},
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "id"
}
]
}
}
}
}
28 changes: 28 additions & 0 deletions tests/translator/output/aws-us-gov/globals_for_simpletable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"Resources": {
"MinimalTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"ProvisionedThroughput": {
"WriteCapacityUnits": 5,
"ReadCapacityUnits": 5
},
"SSESpecification": {
"SSEEnabled": true
},
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "id"
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"Ref": "ReadCapacity"
}
},
"SSESpecification": {
"SSEEnabled": {
"Ref": "EnableSSE"
}
},
"AttributeDefinitions": [
{
"AttributeName": "id",
Expand Down
Loading

0 comments on commit 886dcdc

Please sign in to comment.