Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def to_cloudformation(self, **kwargs):
# merging is literally "last one wins", which works fine because we linearly loop through the template once.
# The de-dupe happens inside `samtranslator.translator.Translator.translate` method when merging results of
# to_cloudformation() to output template.
self._inject_notification_configuration(function, bucket)
self._inject_notification_configuration(function, bucket, bucket_id)
resources.append(S3Bucket.from_dict(bucket_id, bucket))

return resources
Expand Down Expand Up @@ -378,7 +378,7 @@ def _depend_on_lambda_permissions_using_tag(self, bucket, permission):
properties["Tags"] = tags + get_tag_list(dep_tag)
return bucket

def _inject_notification_configuration(self, function, bucket):
def _inject_notification_configuration(self, function, bucket, bucket_id):
base_event_mapping = {"Function": function.get_runtime_attr("arn")}

if self.Filter is not None:
Expand Down Expand Up @@ -407,13 +407,16 @@ def _inject_notification_configuration(self, function, bucket):
notification_config = {}
properties["NotificationConfiguration"] = notification_config

if not isinstance(notification_config, dict):
raise InvalidResourceException(bucket_id, "Invalid type for NotificationConfiguration. Must be a dict.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is dict the right wording here? I only ask because dict is pretty Python specific. How does CloudFormation communicate things like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CloudFormation doesn't seem have a generic name for an object/dict (e.g. it's called NotificationConfiguration type for this case).

Instead of "dict", I think we can just say "Invalid type for NotificationConfiguration". I think it's informative enough for customer to find out how to fix it.


lambda_notifications = notification_config.get("LambdaConfigurations", None)
if lambda_notifications is None:
lambda_notifications = []
notification_config["LambdaConfigurations"] = lambda_notifications

if not isinstance(lambda_notifications, list):
raise InvalidResourceException(self.logical_id, "Invalid type for LambdaConfigurations. Must be a list.")
raise InvalidResourceException(bucket_id, "Invalid type for LambdaConfigurations. Must be a list.")

for event_mapping in event_mappings:
if event_mapping not in lambda_notifications:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,31 @@ Resources:
NotificationConfiguration:
LambdaConfigurations:
Event: s3:ObjectCreated:Put
Function: arn:aws:iam::...
Function: arn:aws:iam::...

AnotherFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://bucket/key
Handler: app.lambdaHandler
Runtime: nodejs14.x
Architectures:
- x86_64
Events:
S3Event:
Type: S3
Properties:
Bucket:
Ref: AnotherBucket
Events: s3:ObjectCreated:*

AnotherBucket:
Type: AWS::S3::Bucket
Properties:
NotificationConfiguration:
- Event: s3:ObjectCreated:*
Function:
Fn::GetAtt:
- AnotherFunction
- Arn

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"errorMessage": "Resource with id [AppFunctionS3Event] is invalid. Invalid type for LambdaConfigurations. Must be a list."
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [AppFunctionS3Event] is invalid. Invalid type for LambdaConfigurations. Must be a list."
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AnotherBucket] is invalid. Invalid type for NotificationConfiguration. Must be a dict. Resource with id [RandomBucket] is invalid. Invalid type for LambdaConfigurations. Must be a list."
}