{ "cells": [ { "cell_type": "markdown", "id": "c21fa110", "metadata": {}, "source": [ "### Add Policies to the Execution Role \n", "* In this sample code, we are going to use several AWS services. Therefore we have to add policies to the notebook execution role. \n", "* Regarding to role and policy, please refer to documents [1](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) and [2](https://docs.aws.amazon.com/IAM/latest/UserGuide/access.html)\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "568abf64", "metadata": {}, "outputs": [], "source": [ "import boto3\n", "from sagemaker import get_execution_role\n", "\n", "role_name = get_execution_role().split('/')[-1]\n", "\n", "iam = boto3.client(\"iam\")\n", "\n", "print(role_name)\n", "policy_arns = [\"arn:aws:iam::aws:policy/AmazonSQSFullAccess\", \n", " \"arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess\",\n", " \"arn:aws:iam::aws:policy/AmazonAPIGatewayAdministrator\",\n", " \"arn:aws:iam::aws:policy/AmazonSNSFullAccess\",\n", " \"arn:aws:iam::aws:policy/AmazonEventBridgeFullAccess\",\n", " \"arn:aws:iam::aws:policy/AWSLambda_FullAccess\"]\n", "\n", "for p in policy_arns: \n", " iam.attach_role_policy(\n", " RoleName = role_name,\n", " PolicyArn = p\n", " )\n", "\n" ] }, { "cell_type": "markdown", "id": "6141850e", "metadata": {}, "source": [ "### Alternate Docker Storage Location " ] }, { "cell_type": "markdown", "id": "6917de3a", "metadata": {}, "source": [ "* docker overlay directory usually will occupy large amount of disk space, change the location to EBS volume " ] }, { "cell_type": "code", "execution_count": null, "id": "39693cf7", "metadata": {}, "outputs": [], "source": [ "%%bash \n", "sudo service docker stop\n", "mkdir ~/SageMaker/docker_disk\n", "sudo mv /var/lib/docker ~/SageMaker/docker_disk/\n", "sudo ln -s ~/SageMaker/docker_disk/docker/ /var/lib/\n", "sudo service docker start" ] }, { "cell_type": "code", "execution_count": null, "id": "14248e97", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "conda_python3", "language": "python", "name": "conda_python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.13" } }, "nbformat": 4, "nbformat_minor": 5 }