Skip to content

Commit f8d0825

Browse files
Determine if a Domain is Lightning domain and configure DomainExecutionRoleCreds profile accordingly since Lightning domains don't have domain execution role
1 parent 99f4f4d commit f8d0825

File tree

2 files changed

+61
-18
lines changed

2 files changed

+61
-18
lines changed

template/v2/dirs/etc/sagemaker-ui/sagemaker_ui_post_startup.sh

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,43 @@ c.Application.logging_config = {
8787
EOT
8888
fi
8989

90-
# Setting this to +x to not log credentials from the response of fetching credentials.
91-
set +x
90+
# Add debug call to get domain info
91+
if [ ! -z "$dataZoneEndPoint" ]; then
92+
domain_response=$(aws datazone get-domain --debug --endpoint-url "$dataZoneEndPoint" --identifier "$dataZoneDomainId" --region "$dataZoneDomainRegion" 2>&1)
93+
94+
else
95+
domain_response=$(aws datazone get-domain --debug --identifier "$dataZoneDomainId" --region "$dataZoneDomainRegion" 2>&1)
96+
fi
9297

93-
# Note: The $? check immediately follows the sagemaker-studio command to ensure we're checking its exit status.
94-
# Adding commands between these lines could lead to incorrect error handling.
95-
response=$(timeout 30 sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id "$dataZoneDomainId" --profile default)
96-
responseStatus=$?
98+
# Check if domain is in express mode
99+
response_body=$(echo "$domain_response" | grep -A1 "Response body:" | tail -n1 | sed 's/^b'\''//;s/'\''$//')
100+
# Remove leading/trailing whitespace and the 'b' prefix
101+
cleaned_response=$(echo "$response_body" | sed 's/\\n//g')
102+
is_express_mode=$(echo "$cleaned_response" | jq -r '.preferences.DOMAIN_MODE == "EXPRESS"')
103+
104+
if [ "$is_express_mode" = "true" ]; then
105+
echo "Domain is in express mode. Using default credentials"
106+
# Use default credentials - no additional configuration needed
107+
aws configure set credential_source EcsContainer --profile DomainExecutionRoleCreds
108+
echo "Successfully configured DomainExecutionRoleCreds profile with default credentials"
109+
else
110+
echo "Domain is not in express mode"
111+
# Setting this to +x to not log credentials from the response of fetching credentials.
112+
set +x
113+
# Note: The $? check immediately follows the sagemaker-studio command to ensure we're checking its exit status.
114+
# Adding commands between these lines could lead to incorrect error handling.
115+
response=$(timeout 30 sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id "$dataZoneDomainId" --profile default)
116+
responseStatus=$?
97117

98-
set -x
118+
set -x
99119

100-
if [ $responseStatus -ne 0 ]; then
120+
if [ $responseStatus -ne 0 ]; then
101121
echo "Failed to fetch domain execution role credentials. Will skip adding new credentials profile: DomainExecutionRoleCreds."
102122
write_status_to_file "error" "Network issue detected. Your domain may be using a public subnet, which affects IDE functionality. Please contact your admin."
103-
else
123+
else
104124
aws configure set credential_process "sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id $dataZoneDomainId --profile default" --profile DomainExecutionRoleCreds
105125
echo "Successfully configured DomainExecutionRoleCreds profile"
126+
fi
106127
fi
107128

108129
# Run AWS CLI command to get the username from DataZone User Profile.

template/v3/dirs/etc/sagemaker-ui/sagemaker_ui_post_startup.sh

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,46 @@ c.Application.logging_config = {
8787
EOT
8888
fi
8989

90-
# Setting this to +x to not log credentials from the response of fetching credentials.
91-
set +x
90+
# Add debug call to get domain info
91+
if [ ! -z "$dataZoneEndPoint" ]; then
92+
domain_response=$(aws datazone get-domain --debug --endpoint-url "$dataZoneEndPoint" --identifier "$dataZoneDomainId" --region "$dataZoneDomainRegion" 2>&1)
9293

93-
# Note: The $? check immediately follows the sagemaker-studio command to ensure we're checking its exit status.
94-
# Adding commands between these lines could lead to incorrect error handling.
95-
response=$(timeout 30 sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id "$dataZoneDomainId" --profile default)
96-
responseStatus=$?
94+
else
95+
domain_response=$(aws datazone get-domain --debug --identifier "$dataZoneDomainId" --region "$dataZoneDomainRegion" 2>&1)
96+
fi
97+
98+
# Check if domain is in express mode
99+
response_body=$(echo "$domain_response" | grep -A1 "Response body:" | tail -n1 | sed 's/^b'\''//;s/'\''$//')
100+
# Remove leading/trailing whitespace and the 'b' prefix
101+
cleaned_response=$(echo "$response_body" | sed 's/\\n//g')
102+
is_express_mode=$(echo "$cleaned_response" | jq -r '.preferences.DOMAIN_MODE == "EXPRESS"')
103+
104+
if [ "$is_express_mode" = "true" ]; then
105+
echo "Domain is in express mode. Using default credentials"
106+
# Use default credentials - no additional configuration needed
107+
aws configure set credential_source EcsContainer --profile DomainExecutionRoleCreds
108+
echo "Successfully configured DomainExecutionRoleCreds profile with default credentials"
109+
else
110+
echo "Domain is not in express mode"
111+
# Setting this to +x to not log credentials from the response of fetching credentials.
112+
set +x
113+
# Note: The $? check immediately follows the sagemaker-studio command to ensure we're checking its exit status.
114+
# Adding commands between these lines could lead to incorrect error handling.
115+
response=$(timeout 30 sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id "$dataZoneDomainId" --profile default)
116+
responseStatus=$?
97117

98-
set -x
118+
set -x
99119

100-
if [ $responseStatus -ne 0 ]; then
120+
if [ $responseStatus -ne 0 ]; then
101121
echo "Failed to fetch domain execution role credentials. Will skip adding new credentials profile: DomainExecutionRoleCreds."
102122
write_status_to_file "error" "Network issue detected. Your domain may be using a public subnet, which affects IDE functionality. Please contact your admin."
103-
else
123+
else
104124
aws configure set credential_process "sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id $dataZoneDomainId --profile default" --profile DomainExecutionRoleCreds
105125
echo "Successfully configured DomainExecutionRoleCreds profile"
126+
fi
106127
fi
107128

129+
108130
# Run AWS CLI command to get the username from DataZone User Profile.
109131
if [ ! -z "$dataZoneEndPoint" ]; then
110132
response=$( aws datazone get-user-profile --endpoint-url "$dataZoneEndPoint" --domain-identifier "$dataZoneDomainId" --user-identifier "$dataZoneUserId" --region "$dataZoneDomainRegion" )

0 commit comments

Comments
 (0)