|
30 | 30 | "\n",
|
31 | 31 | "## Setup\n",
|
32 | 32 | "\n",
|
| 33 | + "### Prerequisites\n", |
| 34 | + "\n", |
| 35 | + "In order to successfully run this notebook, you must first:\n", |
| 36 | + "\n", |
| 37 | + "1. Have an existing KMS key from AWS IAM console or create one ([learn more](http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html)).\n", |
| 38 | + "2. Allow the IAM role used for SageMaker to encrypt and decrypt data with this key from within applications and when using AWS services integrated with KMS ([learn more](http://docs.aws.amazon.com/console/kms/key-users)).\n", |
| 39 | + "\n", |
| 40 | + "We use the `key-id` from the KMS key ARN `arn:aws:kms:region:acct-id:key/key-id`.\n", |
| 41 | + "\n", |
33 | 42 | "### General Setup\n",
|
34 | 43 | "Let's start by specifying:\n",
|
35 | 44 | "* AWS region.\n",
|
36 | 45 | "* The IAM role arn used to give learning and hosting access to your data. See the documentation for how to specify these.\n",
|
37 |
| - "* The S3 bucket that you want to use for training and model data.\n", |
38 |
| - "\n", |
39 |
| - "### KMS key setup\n", |
40 |
| - "1. Use an existing KMS key from AWS IAM console or create one ([learn more](http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html)).\n", |
41 |
| - "2. Allow the IAM role used for SageMaker to encrypt and decrypt data with this key from within applications and when using AWS services integrated with KMS ([learn more](http://docs.aws.amazon.com/console/kms/key-users)).\n", |
42 |
| - "\n", |
43 |
| - "We use the `key-id` from the KMS key ARN `arn:aws:kms:region:acct-id:key/key-id`." |
| 46 | + "* The S3 bucket that you want to use for training and model data." |
44 | 47 | ]
|
45 | 48 | },
|
46 | 49 | {
|
47 | 50 | "cell_type": "code",
|
48 | 51 | "execution_count": null,
|
49 | 52 | "metadata": {
|
| 53 | + "collapsed": true, |
50 | 54 | "isConfigCell": true
|
51 | 55 | },
|
52 | 56 | "outputs": [],
|
|
65 | 69 | "assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n",
|
66 | 70 | "role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)\n",
|
67 | 71 | "\n",
|
68 |
| - "kms_key_id = '<bring your own key-id>'\n", |
| 72 | + "kms_key_id = '<your_kms_key_arn_here>'\n", |
69 | 73 | "\n",
|
70 |
| - "bucket='<s3 bucket>' # put your s3 bucket name here, and create s3 bucket\n", |
| 74 | + "bucket='<your_s3_bucket_name_here>' # put your s3 bucket name here, and create s3 bucket\n", |
71 | 75 | "prefix = 'sagemarker/kms-new'\n",
|
72 | 76 | "# customize to your bucket where you have stored the data\n",
|
73 | 77 | "bucket_path = 'https://s3-{}.amazonaws.com/{}'.format(region,bucket)"
|
|
89 | 93 | {
|
90 | 94 | "cell_type": "code",
|
91 | 95 | "execution_count": null,
|
92 |
| - "metadata": {}, |
| 96 | + "metadata": { |
| 97 | + "collapsed": true |
| 98 | + }, |
93 | 99 | "outputs": [],
|
94 | 100 | "source": [
|
95 | 101 | "!conda install -y -c conda-forge scikit-learn"
|
|
98 | 104 | {
|
99 | 105 | "cell_type": "code",
|
100 | 106 | "execution_count": null,
|
101 |
| - "metadata": {}, |
| 107 | + "metadata": { |
| 108 | + "collapsed": true |
| 109 | + }, |
102 | 110 | "outputs": [],
|
103 | 111 | "source": [
|
104 | 112 | "from sklearn.datasets import load_boston\n",
|
|
125 | 133 | {
|
126 | 134 | "cell_type": "code",
|
127 | 135 | "execution_count": null,
|
128 |
| - "metadata": {}, |
| 136 | + "metadata": { |
| 137 | + "collapsed": true |
| 138 | + }, |
129 | 139 | "outputs": [],
|
130 | 140 | "source": [
|
131 | 141 | "from sklearn.model_selection import train_test_split\n",
|
|
136 | 146 | {
|
137 | 147 | "cell_type": "code",
|
138 | 148 | "execution_count": null,
|
139 |
| - "metadata": {}, |
| 149 | + "metadata": { |
| 150 | + "collapsed": true |
| 151 | + }, |
140 | 152 | "outputs": [],
|
141 | 153 | "source": [
|
142 | 154 | "def write_file(X, y, fname):\n",
|
|
154 | 166 | {
|
155 | 167 | "cell_type": "code",
|
156 | 168 | "execution_count": null,
|
157 |
| - "metadata": {}, |
| 169 | + "metadata": { |
| 170 | + "collapsed": true |
| 171 | + }, |
158 | 172 | "outputs": [],
|
159 | 173 | "source": [
|
160 | 174 | "train_file = 'train.csv'\n",
|
|
175 | 189 | {
|
176 | 190 | "cell_type": "code",
|
177 | 191 | "execution_count": null,
|
178 |
| - "metadata": {}, |
| 192 | + "metadata": { |
| 193 | + "collapsed": true |
| 194 | + }, |
179 | 195 | "outputs": [],
|
180 | 196 | "source": [
|
181 | 197 | "s3 = boto3.client('s3')\n",
|
|
217 | 233 | {
|
218 | 234 | "cell_type": "code",
|
219 | 235 | "execution_count": null,
|
220 |
| - "metadata": {}, |
| 236 | + "metadata": { |
| 237 | + "collapsed": true |
| 238 | + }, |
221 | 239 | "outputs": [],
|
222 | 240 | "source": [
|
223 | 241 | "containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest',\n",
|
224 | 242 | " 'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/xgboost:latest',\n",
|
225 |
| - " 'us-east-2': '825641698319.dkr.ecr.us-east-1.amazonaws.com/xgboost:latest',\n", |
226 |
| - " 'eu-west-1': '685385470294.dkr.ecr.us-east-1.amazonaws.com/xgboost:latest'}\n", |
| 243 | + " 'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/xgboost:latest',\n", |
| 244 | + " 'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/xgboost:latest'}\n", |
227 | 245 | "container = containers[boto3.Session().region_name]"
|
228 | 246 | ]
|
229 | 247 | },
|
230 | 248 | {
|
231 | 249 | "cell_type": "code",
|
232 | 250 | "execution_count": null,
|
233 |
| - "metadata": {}, |
| 251 | + "metadata": { |
| 252 | + "collapsed": true |
| 253 | + }, |
234 | 254 | "outputs": [],
|
235 | 255 | "source": [
|
236 | 256 | "%%time\n",
|
|
323 | 343 | {
|
324 | 344 | "cell_type": "code",
|
325 | 345 | "execution_count": null,
|
326 |
| - "metadata": {}, |
| 346 | + "metadata": { |
| 347 | + "collapsed": true |
| 348 | + }, |
327 | 349 | "outputs": [],
|
328 | 350 | "source": [
|
329 | 351 | "%%time\n",
|
|
362 | 384 | {
|
363 | 385 | "cell_type": "code",
|
364 | 386 | "execution_count": null,
|
365 |
| - "metadata": {}, |
| 387 | + "metadata": { |
| 388 | + "collapsed": true |
| 389 | + }, |
366 | 390 | "outputs": [],
|
367 | 391 | "source": [
|
368 | 392 | "from time import gmtime, strftime\n",
|
|
392 | 416 | {
|
393 | 417 | "cell_type": "code",
|
394 | 418 | "execution_count": null,
|
395 |
| - "metadata": {}, |
| 419 | + "metadata": { |
| 420 | + "collapsed": true |
| 421 | + }, |
396 | 422 | "outputs": [],
|
397 | 423 | "source": [
|
398 | 424 | "%%time\n",
|
|
430 | 456 | {
|
431 | 457 | "cell_type": "code",
|
432 | 458 | "execution_count": null,
|
433 |
| - "metadata": {}, |
| 459 | + "metadata": { |
| 460 | + "collapsed": true |
| 461 | + }, |
434 | 462 | "outputs": [],
|
435 | 463 | "source": [
|
436 | 464 | "runtime_client = boto3.client('sagemaker-runtime')"
|
|
439 | 467 | {
|
440 | 468 | "cell_type": "code",
|
441 | 469 | "execution_count": null,
|
442 |
| - "metadata": {}, |
| 470 | + "metadata": { |
| 471 | + "collapsed": true |
| 472 | + }, |
443 | 473 | "outputs": [],
|
444 | 474 | "source": [
|
445 | 475 | "import sys\n",
|
|
478 | 508 | {
|
479 | 509 | "cell_type": "code",
|
480 | 510 | "execution_count": null,
|
481 |
| - "metadata": {}, |
| 511 | + "metadata": { |
| 512 | + "collapsed": true |
| 513 | + }, |
482 | 514 | "outputs": [],
|
483 | 515 | "source": [
|
484 | 516 | "%%time\n",
|
|
510 | 542 | {
|
511 | 543 | "cell_type": "code",
|
512 | 544 | "execution_count": null,
|
513 |
| - "metadata": {}, |
| 545 | + "metadata": { |
| 546 | + "collapsed": true |
| 547 | + }, |
514 | 548 | "outputs": [],
|
515 | 549 | "source": [
|
516 |
| - "client.delete_endpoint(EndpointName=endpoint_name)" |
| 550 | + "#client.delete_endpoint(EndpointName=endpoint_name)" |
517 | 551 | ]
|
518 |
| - }, |
519 |
| - { |
520 |
| - "cell_type": "code", |
521 |
| - "execution_count": null, |
522 |
| - "metadata": {}, |
523 |
| - "outputs": [], |
524 |
| - "source": [] |
525 | 552 | }
|
526 | 553 | ],
|
527 | 554 | "metadata": {
|
528 | 555 | "kernelspec": {
|
529 |
| - "display_name": "Environment (conda_python3)", |
| 556 | + "display_name": "conda_python3", |
530 | 557 | "language": "python",
|
531 | 558 | "name": "conda_python3"
|
532 | 559 | },
|
|
540 | 567 | "name": "python",
|
541 | 568 | "nbconvert_exporter": "python",
|
542 | 569 | "pygments_lexer": "ipython3",
|
543 |
| - "version": "3.6.3" |
| 570 | + "version": "3.6.2" |
544 | 571 | },
|
545 | 572 | "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."
|
546 | 573 | },
|
|
0 commit comments