Skip to content

Commit 4d11c39

Browse files
committed
Add missing SMUS code changes from v2.6.0 to v3.1.0
1 parent e0b43ed commit 4d11c39

6 files changed

Lines changed: 112 additions & 30 deletions

File tree

build_artifacts/v3/v3.1/v3.1.0/dirs/etc/sagemaker-ui/sagemaker_ui_post_startup.sh

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
#!/bin/bash
22
set -eux
33

4+
# Only run the following commands if SAGEMAKER_APP_TYPE_LOWERCASE is jupyterlab
5+
if [ "${SAGEMAKER_APP_TYPE_LOWERCASE}" = "jupyterlab" ]; then
6+
# Override Jupyter AI config file with specific content only for 2.6
7+
# this is a potential workaround for Q chat issue where the chat does not
8+
# load since it does not pick up the latest config file
9+
NB_USER=sagemaker-user
10+
# Check if Jupyter AI config file exists, override with specific content if so only for 2.6
11+
# this is a potential workaround for Q chat issue
12+
JUPYTER_AI_CONFIG_PATH=/home/${NB_USER}/.local/share/jupyter/jupyter_ai/config.json
13+
JUPYTER_AI_CONFIG_CONTENT='{
14+
"model_provider_id": "amazon-q:Q-Developer",
15+
"embeddings_provider_id": null,
16+
"send_with_shift_enter": false,
17+
"fields": {},
18+
"api_keys": {},
19+
"completions_model_provider_id": null,
20+
"completions_fields": {},
21+
"embeddings_fields": {}
22+
}'
23+
24+
# Overwrite the file if it exists (or create it if it doesn't)
25+
echo "$JUPYTER_AI_CONFIG_CONTENT" > "$JUPYTER_AI_CONFIG_PATH"
26+
fi
27+
428
# Writes script status to file. This file is read by an IDE extension responsible for dispatching UI post-startup-status to the user.
529
write_status_to_file() {
630
local status="$1"
@@ -91,14 +115,14 @@ set +x
91115

92116
# Note: The $? check immediately follows the sagemaker-studio command to ensure we're checking its exit status.
93117
# Adding commands between these lines could lead to incorrect error handling.
94-
response=$( sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id "$dataZoneDomainId" --profile default)
118+
response=$(timeout 30 sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id "$dataZoneDomainId" --profile default)
95119
responseStatus=$?
96120

97121
set -x
98122

99123
if [ $responseStatus -ne 0 ]; then
100124
echo "Failed to fetch domain execution role credentials. Will skip adding new credentials profile: DomainExecutionRoleCreds."
101-
write_status_to_file "error" "Network issue detected. Your domain may be using a public subnet, which affects IDE functionality. Please contact your administrator."
125+
write_status_to_file "error" "Network issue detected. Your domain may be using a public subnet, which affects IDE functionality. Please contact your admin."
102126
else
103127
aws configure set credential_process "sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id $dataZoneDomainId --profile default" --profile DomainExecutionRoleCreds
104128
echo "Successfully configured DomainExecutionRoleCreds profile"
@@ -153,23 +177,28 @@ else
153177
echo readonly LOGNAME >> ~/.bashrc
154178
fi
155179

156-
set -e
157-
158-
# write unexpected error to file if any of the remaining scripts fail.
159-
trap 'write_status_to_file "error" "An unexpected error occurred. Please stop and restart your space to retry."' ERR
160-
161180
# Generate sagemaker pysdk intelligent default config
162181
nohup python /etc/sagemaker/sm_pysdk_default_config.py &
163182
# Only run the following commands if SAGEMAKER_APP_TYPE_LOWERCASE is jupyterlab
164183
if [ "${SAGEMAKER_APP_TYPE_LOWERCASE}" = "jupyterlab" ]; then
184+
# do not fail immediately for non-zero exit code returned
185+
# by start-workflows-container. An expected non-zero exit
186+
# code will be returned if there is not a minimum of 2
187+
# CPU cores available.
165188
# Start workflows local runner
166189
bash /etc/sagemaker-ui/workflows/start-workflows-container.sh
167190

191+
# ensure functions inherit traps and fail immediately
192+
set -eE
193+
194+
# write unexpected error to file if any of the remaining scripts fail.
195+
trap 'write_status_to_file "error" "An unexpected error occurred. Please stop and restart your space to retry."' ERR
196+
168197
# Install conda and pip dependencies if lib mgmt config existing
169198
bash /etc/sagemaker-ui/libmgmt/install-lib.sh $HOME/src
170199

171200
# Install sm-spark-cli
172201
bash /etc/sagemaker-ui/workflows/sm-spark-cli-install.sh
173202
fi
174203

175-
write_status_to_file_on_script_complete
204+
write_status_to_file_on_script_complete

build_artifacts/v3/v3.1/v3.1.0/dirs/etc/sagemaker-ui/workflows/start-workflows-container.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ DZ_DOMAIN_ID=$(jq -r '.AdditionalMetadata.DataZoneDomainId' < $RESOURCE_METADATA
4242
DZ_PROJECT_ID=$(jq -r '.AdditionalMetadata.DataZoneProjectId' < $RESOURCE_METADATA_FILE)
4343
DZ_ENV_ID=$(jq -r '.AdditionalMetadata.DataZoneEnvironmentId' < $RESOURCE_METADATA_FILE)
4444
DZ_DOMAIN_REGION=$(jq -r '.AdditionalMetadata.DataZoneDomainRegion' < $RESOURCE_METADATA_FILE)
45+
DZ_ENDPOINT=$(jq -r '.AdditionalMetadata.DataZoneEndpoint' < $RESOURCE_METADATA_FILE)
4546
DZ_PROJECT_S3PATH=$(jq -r '.AdditionalMetadata.ProjectS3Path' < $RESOURCE_METADATA_FILE)
4647
WORKFLOW_DAG_PATH="/home/sagemaker-user/${HOME_FOLDER_NAME}/workflows/dags"
4748
WORKFLOW_CONFIG_PATH="/home/sagemaker-user/${HOME_FOLDER_NAME}/workflows/config"
@@ -67,7 +68,7 @@ if [ ! -f "${WORKFLOW_HEALTH_PATH}/status.json" ]; then
6768
fi
6869

6970
# Only start local runner if Workflows blueprint is enabled
70-
if [ "$(python /etc/sagemaker-ui/workflows/workflow_client.py check-blueprint --domain-id "$DZ_DOMAIN_ID")" = "False" ]; then
71+
if [ "$(python /etc/sagemaker-ui/workflows/workflow_client.py check-blueprint --region "$DZ_DOMAIN_REGION" --domain-id "$DZ_DOMAIN_ID" --endpoint "$DZ_ENDPOINT")" = "False" ]; then
7172
echo "Workflows blueprint is not enabled. Workflows will not start."
7273
handle_workflows_startup_error 0
7374
fi

build_artifacts/v3/v3.1/v3.1.0/dirs/etc/sagemaker-ui/workflows/workflow_client.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
JUPYTERLAB_URL = "http://default:8888/jupyterlab/default/"
99
WORKFLOWS_API_ENDPOINT = "api/sagemaker/workflows"
1010
TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S.%f%z"
11-
DZ_CLIENT = boto3.client("datazone")
1211

1312

1413
def _validate_response(function_name: str, response: requests.Response):
@@ -49,12 +48,20 @@ def stop_local_runner(session: requests.Session, **kwargs):
4948
return _validate_response("StopLocalRunner", response)
5049

5150

52-
def check_blueprint(domain_id: str, **kwargs):
51+
def check_blueprint(region: str, domain_id: str, endpoint: str, **kwargs):
52+
DZ_CLIENT = boto3.client("datazone")
53+
# add correct endpoint for gamma env
54+
if endpoint != "":
55+
DZ_CLIENT = boto3.client("datazone", endpoint_url=endpoint)
5356
try:
54-
workflow_blueprint = DZ_CLIENT.list_environment_blueprints(domainIdentifier=domain_id, name="Workflows")[
55-
"items"
56-
]
57-
print(str(bool(workflow_blueprint)))
57+
blueprint_id = DZ_CLIENT.list_environment_blueprints(
58+
managed=True, domainIdentifier=domain_id, name="Workflows"
59+
)["items"][0]["id"]
60+
blueprint_config = DZ_CLIENT.get_environment_blueprint_configuration(
61+
domainIdentifier=domain_id, environmentBlueprintIdentifier=blueprint_id
62+
)
63+
enabled_regions = blueprint_config["enabledRegions"]
64+
print(str(region in enabled_regions))
5865
except:
5966
print("False")
6067

@@ -83,6 +90,10 @@ def main():
8390
check_blueprint_parser.add_argument(
8491
"--domain-id", type=str, required=True, help="Datazone Domain ID for blueprint check"
8592
)
93+
check_blueprint_parser.add_argument("--region", type=str, required=True, help="Datazone Domain region")
94+
check_blueprint_parser.add_argument(
95+
"--endpoint", type=str, required=True, help="Datazone endpoint for blueprint check"
96+
)
8697

8798
args = parser.parse_args()
8899

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

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
#!/bin/bash
22
set -eux
33

4+
# Only run the following commands if SAGEMAKER_APP_TYPE_LOWERCASE is jupyterlab
5+
if [ "${SAGEMAKER_APP_TYPE_LOWERCASE}" = "jupyterlab" ]; then
6+
# Override Jupyter AI config file with specific content only for 2.6
7+
# this is a potential workaround for Q chat issue where the chat does not
8+
# load since it does not pick up the latest config file
9+
NB_USER=sagemaker-user
10+
# Check if Jupyter AI config file exists, override with specific content if so only for 2.6
11+
# this is a potential workaround for Q chat issue
12+
JUPYTER_AI_CONFIG_PATH=/home/${NB_USER}/.local/share/jupyter/jupyter_ai/config.json
13+
JUPYTER_AI_CONFIG_CONTENT='{
14+
"model_provider_id": "amazon-q:Q-Developer",
15+
"embeddings_provider_id": null,
16+
"send_with_shift_enter": false,
17+
"fields": {},
18+
"api_keys": {},
19+
"completions_model_provider_id": null,
20+
"completions_fields": {},
21+
"embeddings_fields": {}
22+
}'
23+
24+
# Overwrite the file if it exists (or create it if it doesn't)
25+
echo "$JUPYTER_AI_CONFIG_CONTENT" > "$JUPYTER_AI_CONFIG_PATH"
26+
fi
27+
428
# Writes script status to file. This file is read by an IDE extension responsible for dispatching UI post-startup-status to the user.
529
write_status_to_file() {
630
local status="$1"
@@ -91,14 +115,14 @@ set +x
91115

92116
# Note: The $? check immediately follows the sagemaker-studio command to ensure we're checking its exit status.
93117
# Adding commands between these lines could lead to incorrect error handling.
94-
response=$( sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id "$dataZoneDomainId" --profile default)
118+
response=$(timeout 30 sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id "$dataZoneDomainId" --profile default)
95119
responseStatus=$?
96120

97121
set -x
98122

99123
if [ $responseStatus -ne 0 ]; then
100124
echo "Failed to fetch domain execution role credentials. Will skip adding new credentials profile: DomainExecutionRoleCreds."
101-
write_status_to_file "error" "Network issue detected. Your domain may be using a public subnet, which affects IDE functionality. Please contact your administrator."
125+
write_status_to_file "error" "Network issue detected. Your domain may be using a public subnet, which affects IDE functionality. Please contact your admin."
102126
else
103127
aws configure set credential_process "sagemaker-studio credentials get-domain-execution-role-credential-in-space --domain-id $dataZoneDomainId --profile default" --profile DomainExecutionRoleCreds
104128
echo "Successfully configured DomainExecutionRoleCreds profile"
@@ -153,23 +177,28 @@ else
153177
echo readonly LOGNAME >> ~/.bashrc
154178
fi
155179

156-
set -e
157-
158-
# write unexpected error to file if any of the remaining scripts fail.
159-
trap 'write_status_to_file "error" "An unexpected error occurred. Please stop and restart your space to retry."' ERR
160-
161180
# Generate sagemaker pysdk intelligent default config
162181
nohup python /etc/sagemaker/sm_pysdk_default_config.py &
163182
# Only run the following commands if SAGEMAKER_APP_TYPE_LOWERCASE is jupyterlab
164183
if [ "${SAGEMAKER_APP_TYPE_LOWERCASE}" = "jupyterlab" ]; then
184+
# do not fail immediately for non-zero exit code returned
185+
# by start-workflows-container. An expected non-zero exit
186+
# code will be returned if there is not a minimum of 2
187+
# CPU cores available.
165188
# Start workflows local runner
166189
bash /etc/sagemaker-ui/workflows/start-workflows-container.sh
167190

191+
# ensure functions inherit traps and fail immediately
192+
set -eE
193+
194+
# write unexpected error to file if any of the remaining scripts fail.
195+
trap 'write_status_to_file "error" "An unexpected error occurred. Please stop and restart your space to retry."' ERR
196+
168197
# Install conda and pip dependencies if lib mgmt config existing
169198
bash /etc/sagemaker-ui/libmgmt/install-lib.sh $HOME/src
170199

171200
# Install sm-spark-cli
172201
bash /etc/sagemaker-ui/workflows/sm-spark-cli-install.sh
173202
fi
174203

175-
write_status_to_file_on_script_complete
204+
write_status_to_file_on_script_complete

template/v3/dirs/etc/sagemaker-ui/workflows/start-workflows-container.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ DZ_DOMAIN_ID=$(jq -r '.AdditionalMetadata.DataZoneDomainId' < $RESOURCE_METADATA
4242
DZ_PROJECT_ID=$(jq -r '.AdditionalMetadata.DataZoneProjectId' < $RESOURCE_METADATA_FILE)
4343
DZ_ENV_ID=$(jq -r '.AdditionalMetadata.DataZoneEnvironmentId' < $RESOURCE_METADATA_FILE)
4444
DZ_DOMAIN_REGION=$(jq -r '.AdditionalMetadata.DataZoneDomainRegion' < $RESOURCE_METADATA_FILE)
45+
DZ_ENDPOINT=$(jq -r '.AdditionalMetadata.DataZoneEndpoint' < $RESOURCE_METADATA_FILE)
4546
DZ_PROJECT_S3PATH=$(jq -r '.AdditionalMetadata.ProjectS3Path' < $RESOURCE_METADATA_FILE)
4647
WORKFLOW_DAG_PATH="/home/sagemaker-user/${HOME_FOLDER_NAME}/workflows/dags"
4748
WORKFLOW_CONFIG_PATH="/home/sagemaker-user/${HOME_FOLDER_NAME}/workflows/config"
@@ -67,7 +68,7 @@ if [ ! -f "${WORKFLOW_HEALTH_PATH}/status.json" ]; then
6768
fi
6869

6970
# Only start local runner if Workflows blueprint is enabled
70-
if [ "$(python /etc/sagemaker-ui/workflows/workflow_client.py check-blueprint --domain-id "$DZ_DOMAIN_ID")" = "False" ]; then
71+
if [ "$(python /etc/sagemaker-ui/workflows/workflow_client.py check-blueprint --region "$DZ_DOMAIN_REGION" --domain-id "$DZ_DOMAIN_ID" --endpoint "$DZ_ENDPOINT")" = "False" ]; then
7172
echo "Workflows blueprint is not enabled. Workflows will not start."
7273
handle_workflows_startup_error 0
7374
fi

template/v3/dirs/etc/sagemaker-ui/workflows/workflow_client.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
JUPYTERLAB_URL = "http://default:8888/jupyterlab/default/"
99
WORKFLOWS_API_ENDPOINT = "api/sagemaker/workflows"
1010
TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S.%f%z"
11-
DZ_CLIENT = boto3.client("datazone")
1211

1312

1413
def _validate_response(function_name: str, response: requests.Response):
@@ -49,12 +48,20 @@ def stop_local_runner(session: requests.Session, **kwargs):
4948
return _validate_response("StopLocalRunner", response)
5049

5150

52-
def check_blueprint(domain_id: str, **kwargs):
51+
def check_blueprint(region: str, domain_id: str, endpoint: str, **kwargs):
52+
DZ_CLIENT = boto3.client("datazone")
53+
# add correct endpoint for gamma env
54+
if endpoint != "":
55+
DZ_CLIENT = boto3.client("datazone", endpoint_url=endpoint)
5356
try:
54-
workflow_blueprint = DZ_CLIENT.list_environment_blueprints(domainIdentifier=domain_id, name="Workflows")[
55-
"items"
56-
]
57-
print(str(bool(workflow_blueprint)))
57+
blueprint_id = DZ_CLIENT.list_environment_blueprints(
58+
managed=True, domainIdentifier=domain_id, name="Workflows"
59+
)["items"][0]["id"]
60+
blueprint_config = DZ_CLIENT.get_environment_blueprint_configuration(
61+
domainIdentifier=domain_id, environmentBlueprintIdentifier=blueprint_id
62+
)
63+
enabled_regions = blueprint_config["enabledRegions"]
64+
print(str(region in enabled_regions))
5865
except:
5966
print("False")
6067

@@ -83,6 +90,10 @@ def main():
8390
check_blueprint_parser.add_argument(
8491
"--domain-id", type=str, required=True, help="Datazone Domain ID for blueprint check"
8592
)
93+
check_blueprint_parser.add_argument("--region", type=str, required=True, help="Datazone Domain region")
94+
check_blueprint_parser.add_argument(
95+
"--endpoint", type=str, required=True, help="Datazone endpoint for blueprint check"
96+
)
8697

8798
args = parser.parse_args()
8899

0 commit comments

Comments
 (0)