-
Notifications
You must be signed in to change notification settings - Fork 4
/
optuna-template.yaml
executable file
·491 lines (486 loc) · 15.1 KB
/
optuna-template.yaml
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
AWSTemplateFormatVersion: 2010-09-09
Parameters:
DBClusterName:
Description: 'The cluster name where the parameters will be stored. '
Type: String
Default: optuna-parameter
DatabaseName:
Description: 'The database name where the parameters will be stored. '
Type: String
Default: optuna
AllowedPattern: '([a-z]|[0-9])+'
DBEngine:
Type: String
Default: aurora-mysql
AllowedValues:
- aurora-mysql # compatible with MySQL 5.7
- aurora-postgresql
DBInstanceType:
Description: 'The type of RDS/Aurora instance to be provisioned. '
Type: String
Default: db.t4g.medium
AllowedValues:
- db.t4g.medium
- db.t4g.large
- db.t3.small
- db.t3.medium
- db.t3.large
- db.r6g.large
- db.r6g.xlarge
- db.r6g.2xlarge
- db.r5.large
- db.r5.xlarge
- db.r5.2xlarge
SageMakerInstanceName:
Description: 'Name for the SageMaker notebook. '
Default: optuna-notebook
Type: String
SageMakerInstanceType:
Description: 'The type of SageMaker notebook to be provisioned. '
Type: String
Default: ml.t3.medium
AllowedValues:
- ml.t2.medium
- ml.t3.medium
- ml.t3.large
- ml.t3.xlarge
- ml.t3.2xlarge
- ml.m5.xlarge
- ml.m5.2xlarge
- ml.m5.4xlarge
- ml.m5.12xlarge
- ml.m5.24xlarge
- ml.p2.xlarge
- ml.p2.8xlarge
- ml.p2.16xlarge
- ml.p3.2xlarge
- ml.p3.8xlarge
- ml.p3.16xlarge
EnvironmentName:
Description: An environment name that will be prefixed to resource names
Type: String
Default: optuna
VpcCIDR:
Description: Please enter the IP range (CIDR notation) for this VPC
Type: String
Default: 10.0.0.0/16
PublicSubnet1CIDR:
Description: >-
Please enter the IP range (CIDR notation) for the public subnet in the
first Availability Zone
Type: String
Default: 10.0.0.0/24
PublicSubnet2CIDR:
Description: >-
Please enter the IP range (CIDR notation) for the public subnet in the
second Availability Zone
Type: String
Default: 10.0.2.0/24
PrivateSubnet1CIDR:
Description: >-
Please enter the IP range (CIDR notation) for the private subnet in the
first Availability Zone
Type: String
Default: 10.0.1.0/24
PrivateSubnet2CIDR:
Description: >-
Please enter the IP range (CIDR notation) for the private subnet in the
second Availability Zone
Type: String
Default: 10.0.3.0/24
Mappings:
DBEngineMap:
aurora-mysql:
EngineVersion: '5.7.mysql_aurora.2.10.2'
DefaultParameterGroup: 'aurora-mysql5.7'
Port: 3306
aurora-postgresql:
EngineVersion: '13.4'
DefaultParameterGroup: 'aurora-postgresql10'
Port: 5432
Resources:
VPC:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: !Ref VpcCIDR
Tags:
- Key: Name
Value: !Ref EnvironmentName
Metadata:
'AWS::CloudFormation::Designer':
id: c1a5d4cc-4190-4626-be0d-762be49d9c9a
InternetGateway:
Type: 'AWS::EC2::InternetGateway'
Properties:
Tags:
- Key: Name
Value: !Ref EnvironmentName
Metadata:
'AWS::CloudFormation::Designer':
id: 808edaed-a4f6-4639-98a5-86f3bee3f098
InternetGatewayAttachment:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
Metadata:
'AWS::CloudFormation::Designer':
id: 7226ab70-1a75-436d-8026-d4f0823f53ae
PublicSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select
- 0
- !GetAZs ''
CidrBlock: !Ref PublicSubnet1CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub '${EnvironmentName} Public Subnet (AZ1)'
Metadata:
'AWS::CloudFormation::Designer':
id: b74ea2a6-4268-454a-b4d0-3bd8b25167cf
PublicSubnet2:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select
- 1
- !GetAZs ''
CidrBlock: !Ref PublicSubnet2CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub '${EnvironmentName} Public Subnet (AZ2)'
Metadata:
'AWS::CloudFormation::Designer':
id: 8503e480-d914-44f2-8496-bb0caea8a005
PrivateSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select
- 0
- !GetAZs ''
CidrBlock: !Ref PrivateSubnet1CIDR
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub '${EnvironmentName} Private Subnet (AZ1)'
Metadata:
'AWS::CloudFormation::Designer':
id: 6d674816-f2f5-45e7-9fd5-c19172d2b6ab
PrivateSubnet2:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select
- 1
- !GetAZs ''
CidrBlock: !Ref PrivateSubnet2CIDR
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub '${EnvironmentName} Private Subnet (AZ2)'
Metadata:
'AWS::CloudFormation::Designer':
id: 23ac1c7a-cca4-47e7-8a36-3ba569021a9b
NatGateway1EIP:
Type: 'AWS::EC2::EIP'
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
Metadata:
'AWS::CloudFormation::Designer':
id: 4f1d2eb5-49c8-49c7-b73f-1c90b3527bb8
NatGateway2EIP:
Type: 'AWS::EC2::EIP'
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
Metadata:
'AWS::CloudFormation::Designer':
id: c2aeac7b-a7e6-4c22-8432-8ecf5f127fd7
NatGateway1:
Type: 'AWS::EC2::NatGateway'
Properties:
AllocationId: !GetAtt NatGateway1EIP.AllocationId
SubnetId: !Ref PublicSubnet1
Metadata:
'AWS::CloudFormation::Designer':
id: 8e918ca7-09f8-4f01-8a5d-83e36a1a59c6
NatGateway2:
Type: 'AWS::EC2::NatGateway'
Properties:
AllocationId: !GetAtt NatGateway2EIP.AllocationId
SubnetId: !Ref PublicSubnet2
Metadata:
'AWS::CloudFormation::Designer':
id: f0fedb98-5668-45b4-8ead-0b198c83e144
PublicRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub '${EnvironmentName} Public Routes'
Metadata:
'AWS::CloudFormation::Designer':
id: cb0e8e43-63ee-4d9f-85b2-b9230a80ec71
DefaultPublicRoute:
Type: 'AWS::EC2::Route'
DependsOn: InternetGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
Metadata:
'AWS::CloudFormation::Designer':
id: 2d6d9c30-6a21-45e3-b389-017fef79b9e4
PublicSubnet1RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet1
Metadata:
'AWS::CloudFormation::Designer':
id: 571f66e3-7339-4ebb-b1f3-55132a6fad37
PublicSubnet2RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet2
Metadata:
'AWS::CloudFormation::Designer':
id: 0a3faf8b-f015-46e8-a946-2adddb2143a7
PrivateRouteTable1:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub '${EnvironmentName} Private Routes (AZ1)'
Metadata:
'AWS::CloudFormation::Designer':
id: a8b85010-3ecd-4e15-af79-55dc436161b1
DefaultPrivateRoute1:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId: !Ref PrivateRouteTable1
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway1
Metadata:
'AWS::CloudFormation::Designer':
id: 3ab988d4-6a4c-427a-8143-ff3ae13570e2
PrivateSubnet1RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PrivateRouteTable1
SubnetId: !Ref PrivateSubnet1
Metadata:
'AWS::CloudFormation::Designer':
id: ca4f40df-d867-4a44-ac10-edca2e955bab
PrivateRouteTable2:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub '${EnvironmentName} Private Routes (AZ2)'
Metadata:
'AWS::CloudFormation::Designer':
id: 397aad10-d3b2-4fa1-8e6a-f3b5ff06f6b8
DefaultPrivateRoute2:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId: !Ref PrivateRouteTable2
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway2
Metadata:
'AWS::CloudFormation::Designer':
id: 26f49dc0-7d0f-4de0-a98f-4a585f9b5e87
PrivateSubnet2RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PrivateRouteTable2
SubnetId: !Ref PrivateSubnet2
Metadata:
'AWS::CloudFormation::Designer':
id: a3f7896e-c62e-4ca9-ba10-0fbe25922957
DBCluster:
Type: 'AWS::RDS::DBCluster'
Properties:
Engine: !Ref DBEngine
EngineVersion: !FindInMap
- DBEngineMap
- !Ref DBEngine
- EngineVersion
DBClusterParameterGroupName: !Ref DBClusterParameterGroup
MasterUsername: !Join ['', ['{{resolve:secretsmanager:', !Ref DBSecret, ':SecretString:username}}' ]]
MasterUserPassword: !Join ['', ['{{resolve:secretsmanager:', !Ref DBSecret, ':SecretString:password}}' ]]
DatabaseName: !Ref DatabaseName
DBClusterIdentifier: !Ref DBClusterName
DBSubnetGroupName: !Ref DBSubnetGroup
VpcSecurityGroupIds:
- !GetAtt RDSSecurityGroup.GroupId
Port: !FindInMap [DBEngineMap, !Ref DBEngine, Port]
Metadata:
'AWS::CloudFormation::Designer':
id: d6d32d98-5b8d-4f96-a3f6-d653dd66336b
DBInstance:
Type: AWS::RDS::DBInstance
Properties:
Engine: !Ref DBEngine
DBClusterIdentifier: !Ref DBCluster
DBInstanceClass: !Ref DBInstanceType
DBSubnetGroupName: !Ref DBSubnetGroup
DBParameterGroupName: !Ref DBParameterGroup
DBSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: >-
Private subnets for an Optuna parameter db cluster.
DBSubnetGroupName: parameter-db-subnet
SubnetIds:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
DBClusterParameterGroup:
Type: AWS::RDS::DBClusterParameterGroup
Properties:
Description: DB Cluster Parameter Group for Aurora Cluster
Family: !FindInMap
- DBEngineMap
- !Ref DBEngine
- DefaultParameterGroup
Parameters:
time_zone: Asia/Tokyo
DBParameterGroup:
Type: AWS::RDS::DBParameterGroup
Properties:
Description: DB Parameter Group for Aurora
Family: !FindInMap
- DBEngineMap
- !Ref DBEngine
- DefaultParameterGroup
RDSSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: RDS security group
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref SageMakerSecurityGroup
FromPort: !FindInMap [DBEngineMap, !Ref DBEngine, Port]
ToPort: !FindInMap [DBEngineMap, !Ref DBEngine, Port]
IpProtocol: tcp
VpcId: !Ref VPC
Metadata:
'AWS::CloudFormation::Designer':
id: acb5eaa4-ba49-4e03-ab14-0ec9e6c4dc72
#This is a Secret resource with a randomly generated password in its SecretString JSON.
DBSecret:
Type: AWS::SecretsManager::Secret
Properties:
Name: 'demo/optuna/db'
Description: 'This is the secret for your RDS/Aurora instance'
GenerateSecretString:
SecretStringTemplate: '{"username": "admin"}'
GenerateStringKey: 'password'
PasswordLength: 16
ExcludeCharacters: '"@/\{}'
NotebookInstance:
Type: 'AWS::SageMaker::NotebookInstance'
Properties:
InstanceType: !Ref SageMakerInstanceType
NotebookInstanceName: !Ref SageMakerInstanceName
RoleArn: !GetAtt NotebookExecutionRole.Arn
DirectInternetAccess: Enabled
SubnetId: !Ref PublicSubnet1
SecurityGroupIds:
- !Ref SageMakerSecurityGroup
LifecycleConfigName: !GetAtt NotebookLifecycleConfig.NotebookInstanceLifecycleConfigName
Metadata:
'AWS::CloudFormation::Designer':
id: c90fd14b-d872-4e50-a56f-8675da88eeb2
SageMakerSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: SageMaker Notebook instance / Training contianer security group
VpcId: !Ref VPC
Metadata:
'AWS::CloudFormation::Designer':
id: 2160a120-8184-4562-bccd-aafa12f2add5
NotebookExecutionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- sagemaker.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: get-rds-credentials
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Resource: '*'
Action: '*'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/AmazonSageMakerFullAccess'
Metadata:
'AWS::CloudFormation::Designer':
id: f2c809d6-38e4-4bd5-9c87-a7f57b316daf
NotebookLifecycleConfig:
Type: 'AWS::SageMaker::NotebookInstanceLifecycleConfig'
Properties:
NotebookInstanceLifecycleConfigName: clone-optuna-sample-repository
OnCreate:
- Content: IyEvYmluL2Jhc2gKc3VkbyAtdSBlYzItdXNlciAtaSA8PCdFT0YnCmNkIC9ob21lL2VjMi11c2VyL1NhZ2VNYWtlciAmJiBnaXQgY2xvbmUgaHR0cHM6Ly9naXRodWIuY29tL2F3cy1zYW1wbGVzL2FtYXpvbi1zYWdlbWFrZXItb3B0dW5hLWhwby1ibG9nLmdpdApFT0Y=
Outputs:
VPC:
Description: A reference to the created VPC
Value: !Ref VPC
PublicSubnets:
Description: A list of the public subnets
Value: !Join
- ','
- - !Ref PublicSubnet1
- !Ref PublicSubnet2
PrivateSubnets:
Description: A list of the private subnets
Value: !Join
- ','
- - !Ref PrivateSubnet1
- !Ref PrivateSubnet2
PublicSubnet1:
Description: A reference to the public subnet in the 1st Availability Zone
Value: !Ref PublicSubnet1
PublicSubnet2:
Description: A reference to the public subnet in the 2nd Availability Zone
Value: !Ref PublicSubnet2
PrivateSubnet1:
Description: A reference to the private subnet in the 1st Availability Zone
Value: !Ref PrivateSubnet1
PrivateSubnet2:
Description: A reference to the private subnet in the 2nd Availability Zone
Value: !Ref PrivateSubnet2
SageMakerSecurityGroup:
Description: Security group for SageMaker Notebook instance / Training contianer
Value: !Ref SageMakerSecurityGroup
ClusterEndpoint:
Description: Cluster endpoint
Value: !Sub '${DBCluster.Endpoint.Address}:${DBCluster.Endpoint.Port}'
ClusterName:
Description: Name of cluster
Value: !Ref DBCluster
DBSecretArn:
Description: AWS Secrets Manager secret name for RDS/Aurora
Value: !Ref DBSecret
DatabaseName:
Description: Database name in RDS/Aurora
Value: !Ref DatabaseName