Skip to content

Commit 65dd2e5

Browse files
SSRraymondRaymond Liu
authored andcommitted
fix: when customer role does not have permission to read logs from CW, default to standard logging - Galactus (#1387)
Co-authored-by: Raymond Liu <[email protected]>
1 parent 5c8f6a2 commit 65dd2e5

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/sagemaker/session.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4934,7 +4934,8 @@ def wait_for_endpoint(self, endpoint, poll=DEFAULT_EP_POLL, live_logging=False):
49344934
Returns:
49354935
dict: Return value from the ``DescribeEndpoint`` API.
49364936
"""
4937-
if not live_logging:
4937+
4938+
if not live_logging or not _has_permission_for_live_logging(self.boto_session, endpoint):
49384939
desc = _wait_until(lambda: _deploy_done(self.sagemaker_client, endpoint), poll)
49394940
else:
49404941
cloudwatch_client = self.boto_session.client("logs")
@@ -7614,5 +7615,25 @@ def _flush_log_streams(
76147615
sys.stdout.flush()
76157616

76167617

7618+
def _has_permission_for_live_logging(boto_session, endpoint_name) -> bool:
7619+
"""Validate if customer's role has the right permission to access logs from CloudWatch"""
7620+
try:
7621+
cloudwatch_client = boto_session.client("logs")
7622+
cloudwatch_client.filter_log_events(
7623+
logGroupName=f"/aws/sagemaker/Endpoints/{endpoint_name}",
7624+
logStreamNamePrefix="AllTraffic/",
7625+
)
7626+
return True
7627+
except ClientError as e:
7628+
if e.response["Error"]["Code"] == "AccessDeniedException":
7629+
LOGGER.warning(
7630+
("Failed to enable live logging: %s. Fallback to default logging..."),
7631+
e,
7632+
)
7633+
7634+
return False
7635+
return True
7636+
7637+
76177638
s3_input = deprecated_class(TrainingInput, "sagemaker.session.s3_input")
76187639
ShuffleConfig = deprecated_class(ShuffleConfig, "sagemaker.session.ShuffleConfig")

0 commit comments

Comments
 (0)