Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Raise correct exception when S3 event referring to a bucket whose properties is not dict #2728

Merged
merged 2 commits into from
Dec 14, 2022
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
7 changes: 3 additions & 4 deletions samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,9 @@ def _inject_notification_configuration(self, function, bucket, bucket_id): # ty
lambda_event = make_conditional(function.resource_attributes[CONDITION], lambda_event)
event_mappings.append(lambda_event)

properties = bucket.get("Properties", None)
if properties is None:
properties = {}
bucket["Properties"] = properties
properties = bucket.get("Properties", {})
sam_expect(properties, bucket_id, "").to_be_a_map("Properties should be a map.")
bucket["Properties"] = properties

notification_config = properties.get("NotificationConfiguration", None)
if notification_config is None:
Expand Down
17 changes: 17 additions & 0 deletions tests/translator/input/error_s3_bucket_invalid_properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/thumbnails.zip
Handler: index.generate_thumbails
Runtime: nodejs12.x
Events:
ImageBucket:
Type: S3
Properties:
Bucket: !Ref Bucket
Events: s3:ObjectCreated:*

Bucket:
Type: AWS::S3::Bucket
Properties: This should be a dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Bucket] is invalid. Properties should be a map."
}