Skip to content

Commit 3174f0b

Browse files
authored
Fixing S3 upload errors in opt-in regions (aws#1281)
Passing s3_region as an argument of dask_processor.run() > s3_client = boto3.resource("s3", s3_region) Otherwise will see location constraint error during upload_objects()
1 parent c77d0fb commit 3174f0b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

sagemaker_processing/feature_transformation_with_sagemaker_processing_dask/feature_transformation_with_sagemaker_processing_dask.ipynb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"cells": [
33
{
4-
"attachments": {},
54
"cell_type": "markdown",
65
"metadata": {},
76
"source": [
@@ -216,7 +215,6 @@
216215
")\n",
217216
"\n",
218217
"warnings.filterwarnings(action=\"ignore\", category=DataConversionWarning)\n",
219-
"s3_client = boto3.resource(\"s3\")\n",
220218
"attempts_counter = 3\n",
221219
"attempts = 0\n",
222220
"\n",
@@ -250,12 +248,17 @@
250248
" parser = argparse.ArgumentParser()\n",
251249
" parser.add_argument(\"--train-test-split-ratio\", type=float, default=0.3)\n",
252250
" args, _ = parser.parse_known_args()\n",
253-
"\n",
251+
" \n",
254252
" # Get processor scrip arguments\n",
255253
" args_iter = iter(sys.argv[1:])\n",
256254
" script_args = dict(zip(args_iter, args_iter))\n",
257255
" scheduler_ip = sys.argv[-1]\n",
258256
"\n",
257+
" # S3 client\n",
258+
" s3_region = script_args[\"s3_region\"]\n",
259+
" s3_client = boto3.resource(\"s3\", s3_region)\n",
260+
" print(f'Using the {s3_region} region')\n",
261+
" \n",
259262
" # Start the Dask cluster client\n",
260263
" try:\n",
261264
" client = Client(\"tcp://{ip}:8786\".format(ip=scheduler_ip))\n",
@@ -403,7 +406,9 @@
403406
{
404407
"cell_type": "code",
405408
"execution_count": null,
406-
"metadata": {},
409+
"metadata": {
410+
"scrolled": false
411+
},
407412
"outputs": [],
408413
"source": [
409414
"from sagemaker.processing import ProcessingInput, ScriptProcessor\n",
@@ -429,8 +434,10 @@
429434
" bucket,\n",
430435
" \"s3_output_key_prefix\",\n",
431436
" input_preprocessed_prefix,\n",
437+
" \"s3_region\",\n",
438+
" region\n",
432439
" ],\n",
433-
" logs=True,\n",
440+
" logs=True\n",
434441
")"
435442
]
436443
},
@@ -462,9 +469,9 @@
462469
],
463470
"metadata": {
464471
"kernelspec": {
465-
"display_name": "Python 3",
472+
"display_name": "conda_python3",
466473
"language": "python",
467-
"name": "python3"
474+
"name": "conda_python3"
468475
},
469476
"language_info": {
470477
"codemirror_mode": {
@@ -476,7 +483,7 @@
476483
"name": "python",
477484
"nbconvert_exporter": "python",
478485
"pygments_lexer": "ipython3",
479-
"version": "3.7.4"
486+
"version": "3.6.5"
480487
}
481488
},
482489
"nbformat": 4,

0 commit comments

Comments
 (0)