Skip to content

Commit cada716

Browse files
authored
Scope IAM PassRole to one role name (aws#2963)
* Tensorflow BYO - fix passrole, SM v2 * Tensorflow BYO - fix kernel and formatting * Greengrass - fix passrole * RL markdown helper - fix passrole * Batch BYO - fix passrole, small bugs * Fairness - fix passrole * Fix formatting * Remove duplicate markdown sentence
1 parent d58b3fe commit cada716

File tree

7 files changed

+121
-111
lines changed

7 files changed

+121
-111
lines changed

aws_sagemaker_studio/sagemaker_studio_image_build/tensorflow_bring_your_own/tensorflow_bring_your_own.ipynb

+50-49
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# Building your own TensorFlow container from Amazon SageMaker Studio\n",
88
"\n",
9-
"**STUDIO KERNEL NOTE:** If you are prompted for Kernel, choose 'Python 3 (TensorFlow CPU Optimized) \n",
9+
"**STUDIO KERNEL NOTE:** If you are prompted for Kernel, choose 'Python 3 (TensorFlow 2.1 Python 3.6 CPU Optimized) \n",
1010
"\n",
1111
"With Amazon SageMaker, you can package your own algorithms that can then be trained and deployed in the SageMaker environment. This notebook guides you through an example using TensorFlow that shows you how to build a Docker container for SageMaker and use it for training and inference. \n",
1212
"\n",
@@ -300,9 +300,10 @@
300300
]
301301
},
302302
{
303-
"cell_type": "raw",
303+
"cell_type": "markdown",
304304
"metadata": {},
305305
"source": [
306+
"```\n",
306307
"{\n",
307308
" \"Version\": \"2012-10-17\",\n",
308309
" \"Statement\": [\n",
@@ -323,7 +324,8 @@
323324
" \"Action\": \"sts:AssumeRole\"\n",
324325
" }\n",
325326
" ]\n",
326-
"}"
327+
"}\n",
328+
"```"
327329
]
328330
},
329331
{
@@ -338,17 +340,20 @@
338340
" \n",
339341
" * Open [Policies](https://console.aws.amazon.com/iam/home#/policies) in IAM\n",
340342
" * Click **Create policy**\n",
341-
" * Select the JSON tab and copy/paste the policy below"
343+
" * Select the JSON tab and copy/paste the printed result of the policy below"
342344
]
343345
},
344346
{
345-
"cell_type": "raw",
347+
"cell_type": "code",
348+
"execution_count": null,
346349
"metadata": {},
350+
"outputs": [],
347351
"source": [
348-
"{\n",
352+
"print(\n",
353+
" f\"\"\"{{\n",
349354
" \"Version\": \"2012-10-17\",\n",
350355
" \"Statement\": [\n",
351-
" {\n",
356+
" {{\n",
352357
" \"Effect\": \"Allow\",\n",
353358
" \"Action\": [\n",
354359
" \"codebuild:DeleteProject\",\n",
@@ -357,26 +362,26 @@
357362
" \"codebuild:StartBuild\"\n",
358363
" ],\n",
359364
" \"Resource\": \"arn:aws:codebuild:*:*:project/sagemaker-studio*\"\n",
360-
" },\n",
361-
" {\n",
365+
" }},\n",
366+
" {{\n",
362367
" \"Effect\": \"Allow\",\n",
363368
" \"Action\": \"logs:CreateLogStream\",\n",
364369
" \"Resource\": \"arn:aws:logs:*:*:log-group:/aws/codebuild/sagemaker-studio*\"\n",
365-
" },\n",
366-
" {\n",
370+
" }},\n",
371+
" {{\n",
367372
" \"Effect\": \"Allow\",\n",
368373
" \"Action\": [\n",
369374
" \"logs:GetLogEvents\",\n",
370375
" \"logs:PutLogEvents\"\n",
371376
" ],\n",
372377
" \"Resource\": \"arn:aws:logs:*:*:log-group:/aws/codebuild/sagemaker-studio*:log-stream:*\"\n",
373-
" },\n",
374-
" {\n",
378+
" }},\n",
379+
" {{\n",
375380
" \"Effect\": \"Allow\",\n",
376381
" \"Action\": \"logs:CreateLogGroup\",\n",
377382
" \"Resource\": \"*\"\n",
378-
" },\n",
379-
" {\n",
383+
" }},\n",
384+
" {{\n",
380385
" \"Effect\": \"Allow\",\n",
381386
" \"Action\": [\n",
382387
" \"ecr:CreateRepository\",\n",
@@ -391,48 +396,49 @@
391396
" \"ecr:PutImage\"\n",
392397
" ],\n",
393398
" \"Resource\": \"arn:aws:ecr:*:*:repository/sagemaker-studio*\"\n",
394-
" },\n",
395-
" {\n",
399+
" }},\n",
400+
" {{\n",
396401
" \"Effect\": \"Allow\",\n",
397402
" \"Action\": \"ecr:GetAuthorizationToken\",\n",
398403
" \"Resource\": \"*\"\n",
399-
" },\n",
400-
" {\n",
404+
" }},\n",
405+
" {{\n",
401406
" \"Effect\": \"Allow\",\n",
402407
" \"Action\": [\n",
403408
" \"s3:GetObject\",\n",
404409
" \"s3:DeleteObject\",\n",
405410
" \"s3:PutObject\"\n",
406411
" ],\n",
407412
" \"Resource\": \"arn:aws:s3:::sagemaker-*/*\"\n",
408-
" },\n",
409-
" {\n",
413+
" }},\n",
414+
" {{\n",
410415
" \"Effect\": \"Allow\",\n",
411416
" \"Action\": [\n",
412417
" \"s3:CreateBucket\"\n",
413418
" ],\n",
414419
" \"Resource\": \"arn:aws:s3:::sagemaker*\"\n",
415-
" },\n",
416-
" {\n",
420+
" }},\n",
421+
" {{\n",
417422
" \"Effect\": \"Allow\",\n",
418423
" \"Action\": [\n",
419424
" \"iam:GetRole\",\n",
420425
" \"iam:ListRoles\"\n",
421426
" ],\n",
422427
" \"Resource\": \"*\"\n",
423-
" },\n",
424-
" {\n",
428+
" }},\n",
429+
" {{\n",
425430
" \"Effect\": \"Allow\",\n",
426431
" \"Action\": \"iam:PassRole\",\n",
427-
" \"Resource\": \"arn:aws:iam::*:role/*\",\n",
428-
" \"Condition\": {\n",
429-
" \"StringLikeIfExists\": {\n",
432+
" \"Resource\": \"{role}\",\n",
433+
" \"Condition\": {{\n",
434+
" \"StringLikeIfExists\": {{\n",
430435
" \"iam:PassedToService\": \"codebuild.amazonaws.com\"\n",
431-
" }\n",
432-
" }\n",
433-
" }\n",
436+
" }}\n",
437+
" }}\n",
438+
" }}\n",
434439
" ]\n",
435-
"}"
440+
"}}\"\"\"\n",
441+
")"
436442
]
437443
},
438444
{
@@ -446,7 +452,7 @@
446452
"We now need to attach our policy to the Execution Role attached to this notebook environment. \n",
447453
"\n",
448454
" * Go back to [Roles](https://console.aws.amazon.com/iam/home#/roles) in IAM\n",
449-
" * Select the SageMaker Execution Role from abovee\n",
455+
" * Select the SageMaker Execution Role from above\n",
450456
" * On the **Permissions** tab, click **Attach policies**\n",
451457
" * Search for the Policy we created above `Studio-Image-Build-Policy`\n",
452458
" * Select the policy and click **Attach policy**"
@@ -647,9 +653,10 @@
647653
"\n",
648654
"estimator = Estimator(\n",
649655
" role=role,\n",
650-
" train_instance_count=1,\n",
651-
" train_instance_type=instance_type,\n",
656+
" instance_count=1,\n",
657+
" instance_type=instance_type,\n",
652658
" image_name=ecr_image,\n",
659+
" image_uri=ecr_image,\n",
653660
" hyperparameters=hyperparameters,\n",
654661
")\n",
655662
"\n",
@@ -740,8 +747,6 @@
740747
"import imageio as imageio\n",
741748
"import numpy\n",
742749
"\n",
743-
"from sagemaker.predictor import json_serializer, json_deserializer\n",
744-
"\n",
745750
"image = imageio.imread(\"data/cat.png\")\n",
746751
"print(image.shape)\n",
747752
"\n",
@@ -758,20 +763,16 @@
758763
{
759764
"cell_type": "code",
760765
"execution_count": null,
761-
"metadata": {
762-
"jupyter": {
763-
"source_hidden": true
764-
}
765-
},
766+
"metadata": {},
766767
"outputs": [],
767768
"source": [
768769
"# The request and response format is JSON for TensorFlow Serving.\n",
769770
"# For more information: https://www.tensorflow.org/serving/api_rest#predict_api\n",
770-
"predictor.accept = \"application/json\"\n",
771-
"predictor.content_type = \"application/json\"\n",
771+
"from sagemaker.serializers import JSONSerializer\n",
772+
"from sagemaker.deserializers import JSONDeserializer\n",
772773
"\n",
773-
"predictor.serializer = json_serializer\n",
774-
"predictor.deserializer = json_deserializer\n",
774+
"predictor.serializer = JSONSerializer()\n",
775+
"predictor.deserializer = JSONDeserializer()\n",
775776
"\n",
776777
"# For more information on the predictor class.\n",
777778
"# https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/predictor.py\n",
@@ -821,9 +822,9 @@
821822
"metadata": {
822823
"instance_type": "ml.t3.medium",
823824
"kernelspec": {
824-
"display_name": "Python 3 (TensorFlow CPU Optimized)",
825+
"display_name": "Python 3 (TensorFlow 2.1 Python 3.6 CPU Optimized)",
825826
"language": "python",
826-
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-west-2:236514542706:image/tensorflow-1.15-cpu-py36"
827+
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-2:429704687514:image/tensorflow-2.1-cpu-py36"
827828
},
828829
"language_info": {
829830
"codemirror_mode": {
@@ -835,7 +836,7 @@
835836
"name": "python",
836837
"nbconvert_exporter": "python",
837838
"pygments_lexer": "ipython3",
838-
"version": "3.6.9"
839+
"version": "3.6.13"
839840
}
840841
},
841842
"nbformat": 4,

0 commit comments

Comments
 (0)