From 59da58a5746aac9bdb04470bdf579c9696b85b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Dos=20Santos?= Date: Wed, 29 Nov 2017 10:12:25 -0800 Subject: [PATCH] Fixed the roles from all the notebooks --- .../data_distribution_types.ipynb | 6 +++--- .../handling_kms_encrypted_data.ipynb | 4 ++-- .../kmeans_bring_your_own_model.ipynb | 9 ++++++--- .../parquet_to_recordio_protobuf.ipynb | 4 ++-- .../r_bring_your_own/r_bring_your_own.ipynb | 6 +++--- .../scikit_bring_your_own/scikit_bring_your_own.ipynb | 8 ++++---- .../xgboost_bring_your_own_model.ipynb | 4 ++-- .../factorization_machines_mnist.ipynb | 4 ++-- .../Image-classification-fulltraining.ipynb | 8 +++----- .../Image-classification-transfer-learning.ipynb | 8 +++----- .../lda_topic_modeling/LDA-Introduction.ipynb | 7 +++---- .../linear_learner_mnist/linear_learner_mnist.ipynb | 4 ++-- .../ntm_synthetic/ntm_synthetic.ipynb | 4 ++-- .../pca_mnist/pca_mnist.ipynb | 6 +++--- .../SageMaker-Seq2Seq-Translation-English-German.ipynb | 5 ++--- .../xgboost_abalone/xgboost_abalone.ipynb | 5 ++--- .../xgboost_mnist/xgboost_mnist.ipynb | 5 ++--- .../Breast Cancer Prediction.ipynb | 4 ++-- .../ensemble_modeling/EnsembleLearnerCensusIncome.ipynb | 4 ++-- .../linear_time_series_forecast.ipynb | 6 +++--- .../xgboost_customer_churn/xgboost_customer_churn.ipynb | 4 ++-- .../xgboost_direct_marketing_sagemaker.ipynb | 4 ++-- .../lda_topic_modeling/LDA-Science.ipynb | 7 ++++--- under_development/mxnet_mnist_byom/mxnet_mnist.ipynb | 5 +++-- .../tensorflow_iris_byom/tensorflow_BYOM_iris.ipynb | 5 +++-- 25 files changed, 67 insertions(+), 69 deletions(-) diff --git a/advanced_functionality/data_distribution_types/data_distribution_types.ipynb b/advanced_functionality/data_distribution_types/data_distribution_types.ipynb index 2d2b37921c..eca5974f55 100644 --- a/advanced_functionality/data_distribution_types/data_distribution_types.ipynb +++ b/advanced_functionality/data_distribution_types/data_distribution_types.ipynb @@ -54,9 +54,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", - " \n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()" ] }, { diff --git a/advanced_functionality/handling_kms_encrypted_data/handling_kms_encrypted_data.ipynb b/advanced_functionality/handling_kms_encrypted_data/handling_kms_encrypted_data.ipynb index 8cf2fce4e3..064fc5cda5 100644 --- a/advanced_functionality/handling_kms_encrypted_data/handling_kms_encrypted_data.ipynb +++ b/advanced_functionality/handling_kms_encrypted_data/handling_kms_encrypted_data.ipynb @@ -62,11 +62,11 @@ "import pandas as pd\n", "import numpy as np\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", "region = boto3.Session().region_name\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", + "role = get_execution_role()\n", "\n", "kms_key_id = ''\n", "\n", diff --git a/advanced_functionality/kmeans_bring_your_own_model/kmeans_bring_your_own_model.ipynb b/advanced_functionality/kmeans_bring_your_own_model/kmeans_bring_your_own_model.ipynb index f75da79471..87af810e47 100644 --- a/advanced_functionality/kmeans_bring_your_own_model/kmeans_bring_your_own_model.ipynb +++ b/advanced_functionality/kmeans_bring_your_own_model/kmeans_bring_your_own_model.ipynb @@ -56,14 +56,17 @@ "import boto3\n", "import re\n", " \n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import numpy as np\n", diff --git a/advanced_functionality/parquet_to_recordio_protobuf/parquet_to_recordio_protobuf.ipynb b/advanced_functionality/parquet_to_recordio_protobuf/parquet_to_recordio_protobuf.ipynb index b48bca1e62..747751ccc2 100644 --- a/advanced_functionality/parquet_to_recordio_protobuf/parquet_to_recordio_protobuf.ipynb +++ b/advanced_functionality/parquet_to_recordio_protobuf/parquet_to_recordio_protobuf.ipynb @@ -40,9 +40,9 @@ "import pandas as pd\n", "import numpy as np\n", "import time\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", + "role = get_execution_role()\n", "\n", "bucket = ''\n", "prefix = 'sagemaker/parquet'" diff --git a/advanced_functionality/r_bring_your_own/r_bring_your_own.ipynb b/advanced_functionality/r_bring_your_own/r_bring_your_own.ipynb index 4597235330..5f119a4479 100644 --- a/advanced_functionality/r_bring_your_own/r_bring_your_own.ipynb +++ b/advanced_functionality/r_bring_your_own/r_bring_your_own.ipynb @@ -56,9 +56,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", - " \n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()" ] }, { diff --git a/advanced_functionality/scikit_bring_your_own/scikit_bring_your_own.ipynb b/advanced_functionality/scikit_bring_your_own/scikit_bring_your_own.ipynb index 3edda32194..69bec8c31e 100644 --- a/advanced_functionality/scikit_bring_your_own/scikit_bring_your_own.ipynb +++ b/advanced_functionality/scikit_bring_your_own/scikit_bring_your_own.ipynb @@ -327,13 +327,13 @@ "# Define IAM role\n", "import boto3\n", "import re\n", - " \n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", "\n", "import os\n", "import numpy as np\n", - "import pandas as pd" + "import pandas as pd\n", + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()" ] }, { diff --git a/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb b/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb index 6a6e87eafa..9ce2cfe464 100644 --- a/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb +++ b/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb @@ -55,11 +55,11 @@ "import boto3\n", "import re\n", "import json\n", + "from sagemaker import get_execution_role\n", "\n", "region = boto3.Session().region_name\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", + "role = get_execution_role()\n", "\n", "bucket='' # put your s3 bucket name here, and create s3 bucket\n", "prefix = 'sagemaker/xgboost-byo'\n", diff --git a/introduction_to_amazon_algorithms/factorization_machines_mnist/factorization_machines_mnist.ipynb b/introduction_to_amazon_algorithms/factorization_machines_mnist/factorization_machines_mnist.ipynb index ce7f521120..eec6519b29 100644 --- a/introduction_to_amazon_algorithms/factorization_machines_mnist/factorization_machines_mnist.ipynb +++ b/introduction_to_amazon_algorithms/factorization_machines_mnist/factorization_machines_mnist.ipynb @@ -66,9 +66,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "role = get_execution_role()" ] }, { diff --git a/introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-fulltraining.ipynb b/introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-fulltraining.ipynb index 23dde85f8e..04a2b2f757 100644 --- a/introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-fulltraining.ipynb +++ b/introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-fulltraining.ipynb @@ -46,17 +46,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "%%time\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", + "role = get_execution_role()\n", "\n", "bucket='<>' # customize to your bucket\n", "containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/image-classification:latest',\n", diff --git a/introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-transfer-learning.ipynb b/introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-transfer-learning.ipynb index 68cec496ac..0dfde00d6a 100644 --- a/introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-transfer-learning.ipynb +++ b/introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-transfer-learning.ipynb @@ -45,17 +45,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "%%time\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", + "role = get_execution_role()\n", "\n", "bucket='<>' # customize to your bucket\n", "\n", diff --git a/introduction_to_amazon_algorithms/lda_topic_modeling/LDA-Introduction.ipynb b/introduction_to_amazon_algorithms/lda_topic_modeling/LDA-Introduction.ipynb index cc57ceb06c..e48a154a9b 100644 --- a/introduction_to_amazon_algorithms/lda_topic_modeling/LDA-Introduction.ipynb +++ b/introduction_to_amazon_algorithms/lda_topic_modeling/LDA-Introduction.ipynb @@ -119,13 +119,12 @@ }, "outputs": [], "source": [ + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()\n", "bucket = ''\n", "prefix = 'sagemaker/lda_introduction'\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", - "\n", - "\n", "print('Training input/output will be stored in {}/{}'.format(bucket, prefix))\n", "print('\\nIAM Role: {}'.format(role))" ] diff --git a/introduction_to_amazon_algorithms/linear_learner_mnist/linear_learner_mnist.ipynb b/introduction_to_amazon_algorithms/linear_learner_mnist/linear_learner_mnist.ipynb index b7fcf62ad8..a75eab12ce 100644 --- a/introduction_to_amazon_algorithms/linear_learner_mnist/linear_learner_mnist.ipynb +++ b/introduction_to_amazon_algorithms/linear_learner_mnist/linear_learner_mnist.ipynb @@ -64,9 +64,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "role = get_execution_role()" ] }, { diff --git a/introduction_to_amazon_algorithms/ntm_synthetic/ntm_synthetic.ipynb b/introduction_to_amazon_algorithms/ntm_synthetic/ntm_synthetic.ipynb index 49b43f32f9..c2f3e9f029 100644 --- a/introduction_to_amazon_algorithms/ntm_synthetic/ntm_synthetic.ipynb +++ b/introduction_to_amazon_algorithms/ntm_synthetic/ntm_synthetic.ipynb @@ -67,9 +67,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "role = get_execution_role()" ] }, { diff --git a/introduction_to_amazon_algorithms/pca_mnist/pca_mnist.ipynb b/introduction_to_amazon_algorithms/pca_mnist/pca_mnist.ipynb index 4660089beb..ce9d74c62e 100644 --- a/introduction_to_amazon_algorithms/pca_mnist/pca_mnist.ipynb +++ b/introduction_to_amazon_algorithms/pca_mnist/pca_mnist.ipynb @@ -68,9 +68,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", - " \n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()" ] }, { diff --git a/introduction_to_amazon_algorithms/seq2seq_translation_en-de/SageMaker-Seq2Seq-Translation-English-German.ipynb b/introduction_to_amazon_algorithms/seq2seq_translation_en-de/SageMaker-Seq2Seq-Translation-English-German.ipynb index a2d6485c96..f45a43c8be 100644 --- a/introduction_to_amazon_algorithms/seq2seq_translation_en-de/SageMaker-Seq2Seq-Translation-English-German.ipynb +++ b/introduction_to_amazon_algorithms/seq2seq_translation_en-de/SageMaker-Seq2Seq-Translation-English-German.ipynb @@ -61,10 +61,9 @@ "source": [ "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "# Fetch IAM role\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "role = get_execution_role()" ] }, { diff --git a/introduction_to_amazon_algorithms/xgboost_abalone/xgboost_abalone.ipynb b/introduction_to_amazon_algorithms/xgboost_abalone/xgboost_abalone.ipynb index 236934bf19..386e7ba6c7 100644 --- a/introduction_to_amazon_algorithms/xgboost_abalone/xgboost_abalone.ipynb +++ b/introduction_to_amazon_algorithms/xgboost_abalone/xgboost_abalone.ipynb @@ -52,12 +52,11 @@ "import os\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", + "role = get_execution_role()\n", "region = boto3.Session().region_name\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", - "\n", "bucket='' # put your s3 bucket name here, and create s3 bucket\n", "prefix = 'sagemarker/xgboost-regression'\n", "# customize to your bucket where you have stored the data\n", diff --git a/introduction_to_amazon_algorithms/xgboost_mnist/xgboost_mnist.ipynb b/introduction_to_amazon_algorithms/xgboost_mnist/xgboost_mnist.ipynb index 5791bbfb38..a93d556795 100644 --- a/introduction_to_amazon_algorithms/xgboost_mnist/xgboost_mnist.ipynb +++ b/introduction_to_amazon_algorithms/xgboost_mnist/xgboost_mnist.ipynb @@ -62,13 +62,12 @@ "import copy\n", "import time\n", "from time import gmtime, strftime\n", + "from sagemaker import get_execution_role\n", "\n", + "role = get_execution_role()\n", "\n", "region = boto3.Session().region_name\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", - "\n", "bucket='' # put your s3 bucket name here, and create s3 bucket\n", "prefix = 'sagemarker/xgboost-multiclass-classification'\n", "# customize to your bucket where you have stored the data\n", diff --git a/introduction_to_applying_machine_learning/breast_cancer_prediction/Breast Cancer Prediction.ipynb b/introduction_to_applying_machine_learning/breast_cancer_prediction/Breast Cancer Prediction.ipynb index 607a440d31..3f79b9a7be 100644 --- a/introduction_to_applying_machine_learning/breast_cancer_prediction/Breast Cancer Prediction.ipynb +++ b/introduction_to_applying_machine_learning/breast_cancer_prediction/Breast Cancer Prediction.ipynb @@ -63,9 +63,9 @@ "import os\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", + "role = get_execution_role()\n", "\n", "bucket = ''# enter your s3 bucket where you will copy data and model artifacts\n", "prefix = 'sagemaker/breast_cancer_prediction' # place to upload training files within the bucket" diff --git a/introduction_to_applying_machine_learning/ensemble_modeling/EnsembleLearnerCensusIncome.ipynb b/introduction_to_applying_machine_learning/ensemble_modeling/EnsembleLearnerCensusIncome.ipynb index 4844495a5c..5225dabf31 100644 --- a/introduction_to_applying_machine_learning/ensemble_modeling/EnsembleLearnerCensusIncome.ipynb +++ b/introduction_to_applying_machine_learning/ensemble_modeling/EnsembleLearnerCensusIncome.ipynb @@ -68,9 +68,9 @@ "import boto3\n", "import time\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", + "role = get_execution_role()\n", "\n", "# Now let's define the S3 bucket we'll used for the remainder of this example.\n", "\n", diff --git a/introduction_to_applying_machine_learning/linear_time_series_forecast/linear_time_series_forecast.ipynb b/introduction_to_applying_machine_learning/linear_time_series_forecast/linear_time_series_forecast.ipynb index 1a7bbd3a66..b468dc96d4 100644 --- a/introduction_to_applying_machine_learning/linear_time_series_forecast/linear_time_series_forecast.ipynb +++ b/introduction_to_applying_machine_learning/linear_time_series_forecast/linear_time_series_forecast.ipynb @@ -61,9 +61,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", - " \n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()" ] }, { diff --git a/introduction_to_applying_machine_learning/xgboost_customer_churn/xgboost_customer_churn.ipynb b/introduction_to_applying_machine_learning/xgboost_customer_churn/xgboost_customer_churn.ipynb index 1e6ff54636..17838be9a7 100644 --- a/introduction_to_applying_machine_learning/xgboost_customer_churn/xgboost_customer_churn.ipynb +++ b/introduction_to_applying_machine_learning/xgboost_customer_churn/xgboost_customer_churn.ipynb @@ -59,9 +59,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "role = get_execution_role()" ] }, { diff --git a/introduction_to_applying_machine_learning/xgboost_direct_marketing/xgboost_direct_marketing_sagemaker.ipynb b/introduction_to_applying_machine_learning/xgboost_direct_marketing/xgboost_direct_marketing_sagemaker.ipynb index 1b1cd0f269..046ff01f0c 100644 --- a/introduction_to_applying_machine_learning/xgboost_direct_marketing/xgboost_direct_marketing_sagemaker.ipynb +++ b/introduction_to_applying_machine_learning/xgboost_direct_marketing/xgboost_direct_marketing_sagemaker.ipynb @@ -63,9 +63,9 @@ "# Define IAM role\n", "import boto3\n", "import re\n", + "from sagemaker import get_execution_role\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "role = get_execution_role()" ] }, { diff --git a/scientific_details_of_algorithms/lda_topic_modeling/LDA-Science.ipynb b/scientific_details_of_algorithms/lda_topic_modeling/LDA-Science.ipynb index 2afde21905..e367730481 100644 --- a/scientific_details_of_algorithms/lda_topic_modeling/LDA-Science.ipynb +++ b/scientific_details_of_algorithms/lda_topic_modeling/LDA-Science.ipynb @@ -99,12 +99,13 @@ }, "outputs": [], "source": [ + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()\n", + "\n", "bucket = ''\n", "prefix = 'sagemaker/lda_science'\n", "\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n", - "\n", "\n", "print('Training input/output will be stored in {}/{}'.format(bucket, prefix))\n", "print('\\nIAM Role: {}'.format(role))" diff --git a/under_development/mxnet_mnist_byom/mxnet_mnist.ipynb b/under_development/mxnet_mnist_byom/mxnet_mnist.ipynb index 28a24044d8..a48336fd0a 100644 --- a/under_development/mxnet_mnist_byom/mxnet_mnist.ipynb +++ b/under_development/mxnet_mnist_byom/mxnet_mnist.ipynb @@ -66,8 +66,9 @@ "outputs": [], "source": [ "import boto3, re\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()" ] }, { diff --git a/under_development/tensorflow_iris_byom/tensorflow_BYOM_iris.ipynb b/under_development/tensorflow_iris_byom/tensorflow_BYOM_iris.ipynb index 0429b3e97f..b49bb5e805 100644 --- a/under_development/tensorflow_iris_byom/tensorflow_BYOM_iris.ipynb +++ b/under_development/tensorflow_iris_byom/tensorflow_BYOM_iris.ipynb @@ -48,8 +48,9 @@ "outputs": [], "source": [ "import boto3, re\n", - "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n", - "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)" + "from sagemaker import get_execution_role\n", + "\n", + "role = get_execution_role()" ] }, {