Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional setup reminders, delete env link during offboard #4788

Open
wants to merge 1 commit into
base: default
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ml_ops/sm-datazone_import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ This example contains python scripts to import an existing SageMaker Domain into

## Setup

1. Add the Bring-Your-Own-Domain (BYOD) service model
1. Ensure dependencies are up to date.

Update the CLI. See instructions https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
`aws --version`

Update boto.
`pip install --upgrade -r requirements.txt`
`pip show boto3`

2. Add the Bring-Your-Own-Domain (BYOD) service model

```bash
aws configure add-model --service-model file://resources/datazone-linkedtypes-2018-05-10.normal.json --service-name datazone-byod
```

2. Create a federation role
3. Create a federation role

This role will be used by DataZone to launch the SageMaker Domain. See [BringYourOwnDomainResources.yml](.resources/BringYourOwnDomainResources.yml) for an example.

Expand Down
35 changes: 35 additions & 0 deletions ml_ops/sm-datazone_import/offboard-sagemaker-domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def _offboard_sm_domain(self):
# Firstly, domain remove tags.
sm_domain_tags = [
"AmazonDataZoneDomain",
"AmazonDataZoneProject",
"AmazonDataZoneEnvironment",
"AmazonDataZoneDomainAccount",
"AmazonDataZoneStage",
]
Expand Down Expand Up @@ -138,6 +140,25 @@ def _select_dz_project(self):
)
)

def _select_dz_environment(self):
print("--------------------------------------------------------------------")
print("List of DataZone Environments.")
print("--------------------------------------------------------------------")
dz_env_map = {}
for env in self.dz_client.list_environments(
domainIdentifier=self.dz_domain_id, projectIdentifier=self.dz_project_id
)["items"]:
print(f'Name: {env["name"]}')
dz_env_map[env["name"]] = env["id"]
self.env_name = input("Please provide the name of DataZone environment: ")
self.env_id = dz_env_map[self.env_name]
print(
"Chosen DataZone Environment [{}] with Environment Id [{}]".format(
self.env_name, self.env_id
)
)
return self.env_id

def _delete_linked_items(self):
user_profile_arn = "arn:aws:sagemaker:{}:{}:user-profile/{}/{}".format(
self.region, self.account_id, self.sm_domain_id, self.sm_user_name
Expand Down Expand Up @@ -165,6 +186,18 @@ def _delete_linked_items(self):
itemIdentifiers=[sm_domain_arn],
)

def _delete_env_action_link(self):
for action_link in self.dz_client.list_environment_actions(
domainIdentifier=self.dz_domain_id, environmentIdentifier=self.env_id
)["items"]:
name = action_link["name"]
if "SageMaker" in name:
action_id = action_link["id"]
self.dz_client.delete_environment_action(
domainIdentifier=self.dz_domain_id,
environmentIdentifier=self.env_id,
identifier=action_id)

def _print_results(self):
# Verify no linked entities
print("--------------------------------------------------------------------")
Expand All @@ -182,7 +215,9 @@ def offboard(self):
self._offboard_sm_users()
self._select_dz_domain()
self._select_dz_project()
self._select_dz_environment()
self._delete_linked_items()
self._delete_env_action_link()
self._print_results()


Expand Down