@@ -60,6 +60,9 @@ def _choose_sm_domain(self):
60
60
self .sm_domain_name , self .sm_domain_id
61
61
)
62
62
)
63
+ sm_domain = self .sm_client .describe_domain (DomainId = self .sm_domain_id )
64
+ self .auth_mode = sm_domain ["AuthMode" ]
65
+ self .default_execution_role = sm_domain ["DefaultUserSettings" ]["ExecutionRole" ]
63
66
return self .sm_domain_id
64
67
65
68
def _choose_dz_domain (self ):
@@ -107,15 +110,18 @@ def _choose_dz_project(self):
107
110
)
108
111
return self .dz_project_id
109
112
110
- def _tag_dm_domain (self ):
113
+ def _tag_sm_domain (self ):
111
114
# [3.5 Tagging] Before getting started on byod-e2e, ensure that CX has the SM domain and ExecutionRole's tagged accordingly.
112
115
# 1. Tag the SM domain by admin (DZ DomainId and tag the stage, and domainAccountId)
113
116
# 2. Tag the execution role with DZ domainId and projectId
114
117
118
+ # TODO - remove project/env tags once front end behavior is fixed
115
119
domain_tag = {"Key" : "AmazonDataZoneDomain" , "Value" : self .dz_domain_id }
120
+ project_tag = {"Key" : "AmazonDataZoneProject" , "Value" : self .dz_project_id }
121
+ env_tag = {"Key" : "AmazonDataZoneEnvironment" , "Value" : self .env_id }
116
122
account_tag = {"Key" : "AmazonDataZoneDomainAccount" , "Value" : self .account_id }
117
123
stage_tag = {"Key" : "AmazonDataZoneStage" , "Value" : self .stage }
118
- sm_domain_tags = [domain_tag , account_tag , stage_tag ]
124
+ sm_domain_tags = [domain_tag , project_tag , env_tag , account_tag , stage_tag ]
119
125
sm_domain_arn = "arn:aws:sagemaker:{}:{}:domain/{}" .format (
120
126
self .region , self .account_id , self .sm_domain_id
121
127
)
@@ -156,9 +162,18 @@ def _map_users(self):
156
162
self .sm_user_info = {}
157
163
self .sm_user_info ["name" ] = sm_user_name
158
164
self .sm_user_info ["arn" ] = sm_user_profile_full ["UserProfileArn" ]
159
- self .sm_user_info ["exec_role_arn" ] = sm_user_profile_full ["UserSettings" ][
160
- "ExecutionRole"
161
- ]
165
+ exec_role = None
166
+ if "UserSettings" in sm_user_profile_full :
167
+ user_settings = sm_user_profile_full ["UserSettings" ]
168
+ if "ExecutionRole" in user_settings :
169
+ exec_role = user_settings ["ExecutionRole" ]
170
+
171
+ if exec_role is None :
172
+ print (f'User { sm_user_name } has no execution role set, using default from domain.' )
173
+ exec_role = self .default_execution_role
174
+
175
+ self .sm_user_info ["exec_role_arn" ] = exec_role
176
+
162
177
self .sm_user_info ["id" ] = sm_user_profile_full [
163
178
"HomeEfsFileSystemUid"
164
179
] # e.g. d-7d4uvydb9rcy
@@ -170,7 +185,7 @@ def _map_users(self):
170
185
171
186
# get role name from arn "arn:aws:iam::047923724610:role/service-role/AmazonSageMaker-ExecutionRole-20241008T155288"
172
187
role_name = self .sm_user_info ["exec_role_arn" ][
173
- self .sm_user_info ["exec_role_arn" ].rfind ("/" ) + 1 :
188
+ self .sm_user_info ["exec_role_arn" ].rfind ("/" ) + 1 :
174
189
] # rfind searches from back of string
175
190
self .iam_client .tag_role (RoleName = role_name , Tags = sm_exec_role_tags )
176
191
print (
@@ -360,7 +375,7 @@ def _link_domain(self):
360
375
{
361
376
"itemIdentifier" : f"arn:aws:sagemaker:{ self .region } :{ self .account_id } :domain/{ self .sm_domain_id } " ,
362
377
"itemType" : "SAGEMAKER_DOMAIN" ,
363
- "configuration" : {"AuthMode" : "NonSSO" },
378
+ "configuration" : {"AuthMode" : self . auth_mode },
364
379
"connectedEntities" : [
365
380
{
366
381
"connectedEntityIdentifier" : self .env_id ,
@@ -464,10 +479,10 @@ def import_interactive(self):
464
479
self ._choose_sm_domain ()
465
480
self ._choose_dz_domain ()
466
481
self ._choose_dz_project ()
467
- self ._tag_dm_domain ()
482
+ self ._configure_environment ()
483
+ self ._tag_sm_domain ()
468
484
self ._map_users ()
469
485
self ._configure_blueprint ()
470
- self ._configure_environment ()
471
486
self ._add_environment_action ()
472
487
self ._associate_fed_role ()
473
488
self ._link_domain ()
0 commit comments