-
Notifications
You must be signed in to change notification settings - Fork 142
/
neptune-sagemaker-nested-stack.json
384 lines (384 loc) · 12.9 KB
/
neptune-sagemaker-nested-stack.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
{
"Description": "Amazon SageMaker Neptune notebook instance",
"Parameters": {
"NotebookInstanceType": {
"Description": "SageMaker instance type.",
"Type": "String",
"Default": "ml.t2.medium",
"AllowedValues": [
"ml.t2.medium",
"ml.t2.large",
"ml.t2.xlarge",
"ml.t2.2xlarge",
"ml.m4.xlarge",
"ml.m4.2xlarge",
"ml.m4.4xlarge",
"ml.m4.10xlarge",
"ml.m4.16xlarge"
],
"ConstraintDescription": "Must be a valid SageMaker instance type."
},
"NeptuneClusterEndpoint": {
"Description": "Cluster endpoint of an existing Neptune cluster.",
"Type": "String"
},
"NeptuneReaderEndpoint": {
"Description": "Reader endpoint of an existing Neptune cluster.",
"Type": "String"
},
"NeptuneClusterPort": {
"Description": "OPTIONAL: Port of an existing Neptune cluster (default 8182).",
"Type": "String",
"Default": "8182"
},
"NeptuneClusterVpc": {
"Description": "VPC Id of the VPC in which your Neptune cluster is running.",
"Type": "AWS::EC2::VPC::Id"
},
"NeptuneClusterSubnetId": {
"Description": "Id of one of the subnets in which your Neptune cluster is running.",
"Type": "AWS::EC2::Subnet::Id"
},
"NeptuneClientSecurityGroup": {
"Description": "OPTIONAL: A VPC security group with access to your Neptune cluster. Leave empty only if the Neptune cluster allows access from anywhere.",
"Type": "String"
},
"NeptuneLoadFromS3RoleArn": {
"Description": "ARN of the IAM Role that allows Amazon Neptunes to access Amazon S3 resources.",
"Type": "String"
},
"NotebookContentS3Locations": {
"Description": "OPTIONAL: S3 locations of the notebooks to install into the notebook instance.",
"Type": "String"
},
"StartupScript": {
"Description": "OPTIONAL: Startup script additions for the notebook instance.",
"Type": "String",
"Default": ""
}
},
"Conditions": {
"AddNeptuneClientSecurityGroup": {
"Fn::Not": [
{
"Fn::Equals": [
{
"Ref": "NeptuneClientSecurityGroup"
},
""
]
}
]
},
"InstallNotebookContent": {
"Fn::Not": [
{
"Fn::Equals": [
{
"Ref": "NotebookContentS3Locations"
},
""
]
}
]
}
},
"Resources": {
"SageMakerSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Allow Access",
"VpcId": {
"Ref": "NeptuneClusterVpc"
}
}
},
"NeptuneNotebookInstance": {
"Type": "AWS::SageMaker::NotebookInstance",
"Properties": {
"InstanceType": {
"Ref": "NotebookInstanceType"
},
"SubnetId": {
"Ref": "NeptuneClusterSubnetId"
},
"SecurityGroupIds": {
"Fn::If": [
"AddNeptuneClientSecurityGroup",
[
{
"Ref": "NeptuneClientSecurityGroup"
}
],
[
{
"Fn::GetAtt": [
"SageMakerSecurityGroup",
"GroupId"
]
}
]
]
},
"RoleArn": {
"Fn::GetAtt": [
"ExecutionRole",
"Arn"
]
},
"LifecycleConfigName": {
"Fn::GetAtt": [
"NeptuneNotebookInstanceLifecycleConfig",
"NotebookInstanceLifecycleConfigName"
]
},
"Tags": [
{
"Key": "Name",
"Value": "Neptune-tutorial"
},
{
"Key": "StackId",
"Value": {
"Fn::Sub": "${AWS::StackId}"
}
},
{
"Key": "Stack",
"Value": {
"Fn::Sub": "${AWS::Region}-${AWS::StackName}"
}
},
{
"Key": "Application",
"Value": "NeptuneTutorial"
}
]
}
},
"NeptuneNotebookInstanceLifecycleConfig": {
"Type": "AWS::SageMaker::NotebookInstanceLifecycleConfig",
"Properties": {
"OnCreate": [
{
"Content": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash\n",
"set -e\n",
"mkdir /home/ec2-user/SageMaker/Neptune\n",
"chmod a+rwx /home/ec2-user/SageMaker/Neptune\n"
]
]
}
}
}
],
"OnStart": [
{
"Content": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash\n",
"set -e\n",
"[ -e /home/ec2-user/neptune_ready ] && exit 0\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ msgpack\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ ipython-gremlin\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ gremlinpython\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ --upgrade tornado==4.5.1\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ ipython_unittest\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ jupyter_dojo\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ sparqlwrapper\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ ipython-sparql\n",
"/home/ec2-user/anaconda3/bin/python3 -m pip install --target /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/ ipywidgets\n",
"echo 'export NEPTUNE_CLUSTER_ENDPOINT=",
{
"Ref": "NeptuneClusterEndpoint"
},
"' >> /home/ec2-user/.bashrc\n",
"echo 'export NEPTUNE_READER_ENDPOINT=",
{
"Ref": "NeptuneReaderEndpoint"
},
"' >> /home/ec2-user/.bashrc\n",
"echo 'export NEPTUNE_CLUSTER_PORT=",
{
"Ref": "NeptuneClusterPort"
},
"' >> /home/ec2-user/.bashrc\n",
"echo 'export NEPTUNE_LOAD_FROM_S3_ROLE_ARN=",
{
"Ref": "NeptuneLoadFromS3RoleArn"
},
"' >> /home/ec2-user/.bashrc\n",
"echo 'export AWS_REGION=",
{
"Ref": "AWS::Region"
},
"' >> /home/ec2-user/.bashrc\n",
"echo 'export NOTEBOOK_CONTENT_S3_LOCATION=",
{
"Ref": "NotebookContentS3Locations"
},
"' >> /home/ec2-user/.bashrc\n",
"aws s3 sync s3://aws-neptune-customer-samples/neptune-sagemaker/notebooks /home/ec2-user/SageMaker/Neptune --exclude \"*\" --include \"util/*\"\n",
{
"Fn::If": [
"InstallNotebookContent",
{
"Fn::Join": [
"",
[
"aws s3 cp s3://aws-neptune-customer-samples/neptune-sagemaker/scripts/create-sync-notebook-script.sh .\n",
"chmod a+x create-sync-notebook-script.sh\n",
"./create-sync-notebook-script.sh \"",
{
"Ref": "NotebookContentS3Locations"
},
"\" \"/home/ec2-user/SageMaker/Neptune\"\n"
]
]
},
"# No notebook content\n"
]
},
"chmod --recursive a+rw /home/ec2-user/SageMaker/Neptune/*\n",
"if [ ! -d /home/ec2-user/neptune-tools ]; then\n",
" mkdir /home/ec2-user/neptune-tools\n",
" chmod a+rwx /home/ec2-user/neptune-tools\n",
" cd /home/ec2-user/neptune-tools\n",
" wget https://ftp.osuosl.org/pub/eclipse/rdf4j/eclipse-rdf4j-2.3.2-sdk.zip\n",
" unzip eclipse-rdf4j-2.3.2-sdk.zip\n",
" rm eclipse-rdf4j-2.3.2-sdk.zip\n",
" wget https://archive.apache.org/dist/tinkerpop/3.3.3/apache-tinkerpop-gremlin-console-3.3.3-bin.zip\n",
" unzip apache-tinkerpop-gremlin-console-3.3.3-bin.zip\n",
" rm apache-tinkerpop-gremlin-console-3.3.3-bin.zip\n",
" chmod a+rwx apache-tinkerpop-gremlin-console-3.3.3/conf\n",
" cd apache-tinkerpop-gremlin-console-3.3.3/conf\n",
" echo hosts: [",
{
"Ref": "NeptuneClusterEndpoint"
},
"] >> neptune-remote.yaml\n",
" echo port: ",
{
"Ref": "NeptuneClusterPort"
},
" >> neptune-remote.yaml\n",
" echo serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}",
" >> neptune-remote.yaml\n",
"fi\n",
{
"Ref": "StartupScript"
},
"\n",
"sudo touch /home/ec2-user/neptune_ready"
]
]
}
}
}
]
}
},
"ExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"sagemaker.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": "sagemakerneptunepolicy",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sagemaker:*",
"cloudwatch:PutMetricData",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
"logs:GetLogEvents"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::*"
]
}
]
}
}
]
}
}
},
"Outputs": {
"NeptuneNotebookInstanceId": {
"Value": {
"Ref": "NeptuneNotebookInstance"
}
},
"NeptuneNotebook": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Fn::Select": [
1,
{
"Fn::Split": [
"/",
{
"Ref": "NeptuneNotebookInstance"
}
]
}
]
},
".notebook.",
{
"Ref": "AWS::Region"
},
".sagemaker.aws/"
]
]
}
},
"NeptuneNotebookInstanceLifecycleConfigId": {
"Value": {
"Ref": "NeptuneNotebookInstanceLifecycleConfig"
}
}
}
}