Add create notifications helper method - #6113
Open
mujtaba1747 wants to merge 6 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improves SNS/EventBridge notification setup in sagemaker-train and makes permission failures clearer.
File changed: notifications.py
Add create_notification_topic(topic_name, sagemaker_session): creates an SNS topic and applies an access policy that lets EventBridge in the same account publish to it. The returned ARN can be passed straight to enable_notifications, so callers no longer have to configure the topic policy by hand.
Add _build_topic_policy(topic_arn, account_id) helper that assembles the policy: the default owner statement (standard SNS actions scoped to the owning account via AWS:SourceAccount) plus an explicit statement granting the EventBridge service principal (events.amazonaws.com) SNS:Publish, also scoped by AWS:SourceAccount.
Tighten error handling in enable_notifications: replace the broad except Exception (which wrapped every failure in a generic ValueError) with a targeted except ClientError. On AccessDenied/AccessDeniedException it raises a concise PermissionError pointing at the missing events:PutTargets permission; all other errors propagate unchanged.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.