- Newest
- Most votes
- Most comments
Specifically, /opt/ml/metadata/resource-metadata.json doesn't provide UserProfileName in SageMaker AI Studio (non-classic), but it does provide the information you'd need to know what domain (DomainId), space (SpaceName), and app you're in.
If you're in a private space, then you can run aws sagemaker describe-space --domain-id {DomainId} --space-name {SpaceName} and take .OwnershipSettings.OwnerUserProfileName from the result.
If you're in a domain shared space, then the space owner might not be the currently logged-in user... In which case if aws sts get-caller-identity is not telling you anything useful, then I think you might have to explore JupyterLab extensions to dig the information out of the JavaScript/UI side of JupyterLab and expose it into the Python/kernel side? I see that there's a jupyterlab/default/api/me API call when loading the page which retrieves the current user's name - but not sure how you could fetch this information into the Python kernel.
In SageMaker Studio, retrieving the user identity from a space like JupyterLab or CodeEditor is possible, but it requires a different approach compared to classic notebooks. Here's what you need to know:
-
The aws:sourceIdentity field: The ability to propagate the user profile name as sourceIdentity in Studio is not enabled by default. To use this feature, it needs to be explicitly enabled at the domain level using the AWS CLI during domain creation or update. Once enabled, administrators can view the user profile in AWS CloudTrail logs for accessed services.
-
Accessing metadata in Studio notebooks: Unlike classic notebooks, Studio notebooks don't have the /opt/ml/metadata/resource-metadata.json file with the UserProfileName. However, you can still access some metadata information in Studio notebooks:
- Open a terminal in your Studio notebook.
- Navigate to /opt/ml/metadata/
- Use the command 'cat resource-metadata.json' to display the contents.
The file should contain information such as AppType, DomainId, UserProfileName, ResourceArn, ResourceName, and AppImageVersion.
- Alternative method: If you're unable to find the user identity information in the resource-metadata.json file, you can use the DescribeUserProfile API operation. This operation returns information about a specific user profile, including a SingleSignOnUserIdentifier, which is the IAM Identity Center user identifier.
Remember that the availability and exact method of accessing user identity information may vary depending on your specific SageMaker Studio setup and configuration. If you're still unable to retrieve the user identity, you may need to consult with your AWS administrator to ensure that the necessary configurations and permissions are in place.
Sources
Get Studio Classic Notebook and App Metadata - Amazon SageMaker AI
Turn on sourceIdentity in CloudTrail logs for SageMaker AI Studio Classic - Amazon SageMaker AI
DescribeUserProfile - Amazon SageMaker
answered 2 years ago
Relevant content
asked 2 years ago
