Skip to content

Commit 8c56b27

Browse files
committed
Updated: kmeans_byom from feedback
1 parent e8a877c commit 8c56b27

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

advanced_functionality/kmeans_bring_your_own_model/kmeans_bring_your_own_model.ipynb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
"---\n",
3434
"## Setup\n",
3535
"\n",
36+
"_This notebook was created and tested on an ml.m4.xlarge notebook instance._\n",
37+
"\n",
3638
"Let's start by specifying:\n",
3739
"\n",
38-
"- The IAM role arn used to give learning and hosting access to your data. See the documentation for how to create these. Note, if more than one role is required for notebook instances, training, and/or hosting, please replace the boto call with a the appropriate full IAM role arn string.\n",
39-
"- The S3 bucket and prefix where you'll be storing your model data."
40+
"- The S3 bucket and prefix that you want to use for training and model data. This should be within the same region as the Notebook Instance, training, and hosting.\n",
41+
"- The IAM role arn used to give training and hosting access to your data. See the documentation for how to create these. Note, if more than one role is required for notebook instances, training, and/or hosting, please replace the boto regexp with a the appropriate full IAM role arn string(s)."
4042
]
4143
},
4244
{
@@ -47,12 +49,15 @@
4749
},
4850
"outputs": [],
4951
"source": [
50-
"import boto3\n",
51-
"\n",
52-
"role = boto3.client('iam').list_instance_profiles()['InstanceProfiles'][0]['Roles'][0]['Arn']\n",
53-
"\n",
5452
"bucket = '<your_s3_bucket_name_here>'\n",
55-
"prefix = 'sagemaker/kmeans_byom'"
53+
"prefix = 'sagemaker/kmeans_byom'\n",
54+
" \n",
55+
"# Define IAM role\n",
56+
"import boto3\n",
57+
"import re\n",
58+
" \n",
59+
"assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n",
60+
"role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)"
5661
]
5762
},
5863
{
@@ -100,7 +105,7 @@
100105
"\n",
101106
"### Data\n",
102107
"\n",
103-
"For simplicity, we'll utilize the MNIST handwritten digit dataset."
108+
"For simplicity, we'll utilize the MNIST dataset. This includes roughly 70K 28 x 28 pixel images of handwritten digits from 0 to 9. More detail can be found [here](https://en.wikipedia.org/wiki/MNIST_database)."
104109
]
105110
},
106111
{
@@ -351,10 +356,18 @@
351356
"\n",
352357
"This notebook showed how to seed a pre-existing model in an already built container. This functionality could be replicated with other Amazon SageMaker Algorithms, as well as the TensorFlow and MXNet containers. Although this is certainly an easy method to bring your own model, it is not likely to provide the flexibility of a bringing your own scoring container. Please refer to other example notebooks which show how to dockerize your own training and scoring could which could be modified appropriately to your use case."
353358
]
359+
},
360+
{
361+
"cell_type": "code",
362+
"execution_count": null,
363+
"metadata": {},
364+
"outputs": [],
365+
"source": [
366+
"sm.delete_endpoint(EndpointName=kmeans_endpoint)"
367+
]
354368
}
355369
],
356370
"metadata": {
357-
"notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.",
358371
"kernelspec": {
359372
"display_name": "Environment (conda_mxnet_p36)",
360373
"language": "python",
@@ -371,7 +384,8 @@
371384
"nbconvert_exporter": "python",
372385
"pygments_lexer": "ipython3",
373386
"version": "3.6.3"
374-
}
387+
},
388+
"notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
375389
},
376390
"nbformat": 4,
377391
"nbformat_minor": 2

0 commit comments

Comments
 (0)