diff --git a/packages/@aws-cdk/custom-resource-handlers/lib/aws-s3/notifications-resource-handler/index.py b/packages/@aws-cdk/custom-resource-handlers/lib/aws-s3/notifications-resource-handler/index.py index ce22358f9ee2d..ea3df6a2334c1 100644 --- a/packages/@aws-cdk/custom-resource-handlers/lib/aws-s3/notifications-resource-handler/index.py +++ b/packages/@aws-cdk/custom-resource-handlers/lib/aws-s3/notifications-resource-handler/index.py @@ -35,8 +35,13 @@ def handle_managed(request_type, notification_configuration): return notification_configuration def handle_unmanaged(bucket, stack_id, request_type, notification_configuration, old): + def get_id(n): + n['Id'] = '' + strToHash=json.dumps(n, sort_keys=True).replace("'Name:' 'prefix'", "'Name:' 'Prefix'").replace("'Name:' 'suffix'", "'Name:' 'Suffix'") + return f"{stack_id}-{hash(strToHash)}" + def with_id(n): - n['Id'] = f"{stack_id}-{hash(json.dumps(n, sort_keys=True))}" + n['Id'] = get_id(n) return n # find external notifications @@ -45,9 +50,9 @@ def with_id(n): for t in CONFIGURATION_TYPES: if request_type == 'Update': ids = [with_id(n) for n in old.get(t, [])] - old_incoming_ids = [n['Id'] for n in ids] + old_incoming_ids = [get_id(n) for n in old.get(t, [])] # if the notification was created by us, we know what id to expect so we can filter by it. - external_notifications[t] = [n for n in existing_notifications.get(t, []) if not n['Id'] in old_incoming_ids] + external_notifications[t] = [n for n in existing_notifications.get(t, []) if not get_id(n) in old_incoming_ids] elif request_type == 'Create': # if this is a create event then all existing notifications are external external_notifications[t] = [n for n in existing_notifications.get(t, [])]