Skip to content

Commit 07653c6

Browse files
authored
Use Session().default_bucket() by default with Python SDK notebooks (aws#430)
1 parent 2697b39 commit 07653c6

File tree

5 files changed

+46
-38
lines changed

5 files changed

+46
-38
lines changed

sagemaker-python-sdk/1P_kmeans_highlevel/kmeans_mnist.ipynb

+6-5
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"\n",
4141
"Here we set up the linkage and authentication to AWS services. There are two parts to this:\n",
4242
"\n",
43-
"1. The role(s) used to give learning and hosting access to your data. Here we extract the role you created earlier for accessing your notebook. See the documentation if you want to specify a different role\n",
44-
"1. The S3 bucket name and locations that you want to use for training and model data."
43+
"1. The role(s) used to give learning and hosting access to your data. Here we extract the role you created earlier for accessing your notebook. See the documentation if you want to specify a different role.\n",
44+
"1. The S3 bucket name that you want to use for training and model data. Here we use a default in the form of `sagemaker-{region}-{AWS account ID}`, but you may specify a different one if you wish."
4545
]
4646
},
4747
{
@@ -53,9 +53,10 @@
5353
"outputs": [],
5454
"source": [
5555
"from sagemaker import get_execution_role\n",
56+
"from sagemaker.session import Session\n",
5657
"\n",
5758
"role = get_execution_role()\n",
58-
"bucket='<bucket-name>'"
59+
"bucket = Session().default_bucket()"
5960
]
6061
},
6162
{
@@ -279,7 +280,7 @@
279280
],
280281
"metadata": {
281282
"kernelspec": {
282-
"display_name": "Environment (conda_python3)",
283+
"display_name": "conda_python3",
283284
"language": "python",
284285
"name": "conda_python3"
285286
},
@@ -293,7 +294,7 @@
293294
"name": "python",
294295
"nbconvert_exporter": "python",
295296
"pygments_lexer": "ipython3",
296-
"version": "3.6.3"
297+
"version": "3.6.5"
297298
},
298299
"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."
299300
},

sagemaker-python-sdk/1P_kmeans_lowlevel/kmeans_mnist_lowlevel.ipynb

+5-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"Here we set up the linkage and authentication to AWS services. There are two parts to this:\n",
4545
"\n",
4646
"1. The role(s) used to give learning and hosting access to your data. See the documentation for how to specify these.\n",
47-
"1. The S3 bucket name and location that you want to use for training and model data."
47+
"1. The S3 bucket name that you want to use for training and model data. Here we use a default in the form of `sagemaker-{region}-{AWS account ID}`, but you may specify a different one if you wish."
4848
]
4949
},
5050
{
@@ -57,9 +57,10 @@
5757
"outputs": [],
5858
"source": [
5959
"from sagemaker import get_execution_role\n",
60+
"from sagemaker.session import Session\n",
6061
"\n",
6162
"role = get_execution_role()\n",
62-
"bucket='<bucket-name>'"
63+
"bucket = Session().default_bucket()"
6364
]
6465
},
6566
{
@@ -496,7 +497,7 @@
496497
],
497498
"metadata": {
498499
"kernelspec": {
499-
"display_name": "Environment (conda_python3)",
500+
"display_name": "conda_python3",
500501
"language": "python",
501502
"name": "conda_python3"
502503
},
@@ -510,7 +511,7 @@
510511
"name": "python",
511512
"nbconvert_exporter": "python",
512513
"pygments_lexer": "ipython3",
513-
"version": "3.6.3"
514+
"version": "3.6.5"
514515
},
515516
"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."
516517
},

sagemaker-python-sdk/mxnet_mnist/mxnet_mnist.ipynb

+13-17
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@
2323
"outputs": [],
2424
"source": [
2525
"from sagemaker import get_execution_role\n",
26+
"from sagemaker.session import Session\n",
2627
"\n",
27-
"#Bucket location to save your custom code in tar.gz format.\n",
28-
"custom_code_upload_location = 's3://<bucket-name>/customcode/mxnet'\n",
28+
"# S3 bucket for saving code and model artifacts.\n",
29+
"# Feel free to specify a different bucket here if you wish.\n",
30+
"bucket = Session().default_bucket()\n",
2931
"\n",
30-
"#Bucket location where results of model training are saved.\n",
31-
"model_artifacts_location = 's3://<bucket-name>/artifacts'\n",
32+
"# Location to save your custom code in tar.gz format.\n",
33+
"custom_code_upload_location = 's3://{}/customcode/mxnet'.format(bucket)\n",
3234
"\n",
33-
"#IAM execution role that gives SageMaker access to resources in your AWS account.\n",
34-
"#We can use the SageMaker Python SDK to get the role from our notebook environment. \n",
35+
"# Location where results of model training are saved.\n",
36+
"model_artifacts_location = 's3://{}/artifacts'.format(bucket)\n",
37+
"\n",
38+
"# IAM execution role that gives SageMaker access to resources in your AWS account.\n",
39+
"# We can use the SageMaker Python SDK to get the role from our notebook environment. \n",
3540
"role = get_execution_role()"
3641
]
3742
},
@@ -234,20 +239,11 @@
234239
"\n",
235240
"sagemaker.Session().delete_endpoint(predictor.endpoint)"
236241
]
237-
},
238-
{
239-
"cell_type": "code",
240-
"execution_count": null,
241-
"metadata": {
242-
"collapsed": true
243-
},
244-
"outputs": [],
245-
"source": []
246242
}
247243
],
248244
"metadata": {
249245
"kernelspec": {
250-
"display_name": "Environment (conda_mxnet_p36)",
246+
"display_name": "conda_mxnet_p36",
251247
"language": "python",
252248
"name": "conda_mxnet_p36"
253249
},
@@ -261,7 +257,7 @@
261257
"name": "python",
262258
"nbconvert_exporter": "python",
263259
"pygments_lexer": "ipython3",
264-
"version": "3.6.3"
260+
"version": "3.6.5"
265261
},
266262
"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."
267263
},

sagemaker-python-sdk/tensorflow_iris_dnn_classifier_using_estimators/tensorflow_iris_dnn_classifier_using_estimators.ipynb

+11-6
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@
9898
"outputs": [],
9999
"source": [
100100
"from sagemaker import get_execution_role\n",
101+
"from sagemaker.session import Session\n",
101102
"\n",
102-
"#Bucket location to save your custom code in tar.gz format.\n",
103-
"custom_code_upload_location = 's3://<bucket-name>/customcode/tensorflow_iris'\n",
103+
"# S3 bucket for saving code and model artifacts.\n",
104+
"# Feel free to specify a different bucket here if you wish.\n",
105+
"bucket = Session().default_bucket()\n",
104106
"\n",
105-
"#Bucket location where results of model training are saved.\n",
106-
"model_artifacts_location = 's3://<bucket-name>/artifacts'\n",
107+
"# Location to save your custom code in tar.gz format.\n",
108+
"custom_code_upload_location = 's3://{}/customcode/tensorflow_iris'.format(bucket)\n",
109+
"\n",
110+
"# Location where results of model training are saved.\n",
111+
"model_artifacts_location = 's3://{}/artifacts'.format(bucket)\n",
107112
"\n",
108113
"#IAM execution role that gives SageMaker access to resources in your AWS account.\n",
109114
"role = get_execution_role()"
@@ -416,7 +421,7 @@
416421
],
417422
"metadata": {
418423
"kernelspec": {
419-
"display_name": "Environment (conda_tensorflow_p27)",
424+
"display_name": "conda_tensorflow_p27",
420425
"language": "python",
421426
"name": "conda_tensorflow_p27"
422427
},
@@ -430,7 +435,7 @@
430435
"name": "python",
431436
"nbconvert_exporter": "python",
432437
"pygments_lexer": "ipython2",
433-
"version": "2.7.11"
438+
"version": "2.7.15"
434439
},
435440
"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."
436441
},

sagemaker-python-sdk/tensorflow_pipemode_example/tensorflow_pipemode_example.ipynb

+11-6
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@
3232
"outputs": [],
3333
"source": [
3434
"from sagemaker import get_execution_role\n",
35-
"#IAM execution role that gives SageMaker access to resources in your AWS account.\n",
36-
"role = get_execution_role()\n",
35+
"from sagemaker.session import Session\n",
3736
"\n",
38-
"#Bucket location to save your custom code in tar.gz format.\n",
39-
"bucket = '<bucket-name>'\n",
37+
"# S3 bucket for saving code and model artifacts.\n",
38+
"# Feel free to specify a different bucket here if you wish.\n",
39+
"bucket = Session().default_bucket()\n",
40+
"\n",
41+
"# Location to save your custom code in tar.gz format.\n",
4042
"custom_code_upload_location = 's3://{}/customcode/tensorflow_pipemode'.format(bucket)\n",
4143
"\n",
42-
"#Bucket location where results of model training are saved.\n",
43-
"model_artifacts_location = 's3://{}/artifacts'.format(bucket)"
44+
"# Location where results of model training are saved.\n",
45+
"model_artifacts_location = 's3://{}/artifacts'.format(bucket)\n",
46+
"\n",
47+
"# IAM execution role that gives SageMaker access to resources in your AWS account.\n",
48+
"role = get_execution_role()"
4449
]
4550
},
4651
{

0 commit comments

Comments
 (0)