@@ -6,6 +6,7 @@ import glue = require('@aws-cdk/aws-glue');
66import s3 = require( '@aws-cdk/aws-s3' ) ;
77import s3assets = require( '@aws-cdk/aws-s3-assets' ) ;
88import sagemaker = require( '@aws-cdk/aws-sagemaker' ) ;
9+ import { DataSetStack , DataSetStackProps } from './dataset-stack' ;
910
1011export interface AnalyticsStackProps extends cdk . StackProps {
1112 targetVpc : ec2 . Vpc
@@ -14,6 +15,8 @@ export interface AnalyticsStackProps extends cdk.StackProps{
1415
1516export class AnalyticsStack extends cdk . Stack {
1617
18+ public readonly NotebookRole : iam . Role ;
19+
1720 constructor ( scope : cdk . Construct , id : string , props : AnalyticsStackProps ) {
1821 super ( scope , id , props ) ;
1922
@@ -22,11 +25,16 @@ export class AnalyticsStack extends cdk.Stack {
2225 vpc : props . targetVpc
2326 } ) ;
2427
28+ const athenaSagingDirectory = new s3 . Bucket ( this , 'athenaStagingDir' , { } ) ;
29+
30+
2531
2632 const lifecycleCode = [
2733 { "content" : cdk . Fn . base64 ( `
2834 wget -O /home/ec2-user/SageMaker/opentargets.chembl.example.ipynb https://raw.githubusercontent.com/paulu-aws/chembl-opentargets-data-lake-example/master/scripts/sagemaker.opentargets.chembl.example.ipynb
29- chown ec2-user /home/ec2-user/SageMaker/opentargets.chembl.example.ipynb
35+ sudo chown ec2-user /home/ec2-user/SageMaker/opentargets.chembl.example.ipynb
36+ sed -i 's/XXXXAthenaStagingDirectoryXXXX/${ athenaSagingDirectory . bucketName } /g' opentargets.chembl.example.ipynb
37+ sed -i 's/XXXXAthenaRegionXXXX/${ cdk . Stack . of ( this ) . region } /g' opentargets.chembl.example.ipynb
3038 ` ) }
3139 ] ;
3240 const sageMakerIntanceLifecyclePolicy = new sagemaker . CfnNotebookInstanceLifecycleConfig ( this , 'notebookLifecyclePolicy' , {
@@ -35,19 +43,20 @@ export class AnalyticsStack extends cdk.Stack {
3543
3644 } ) ;
3745
38- const sageMakerInstanceRole = new iam . Role ( this , 'notebookInstanceRole' , {
46+ this . NotebookRole = new iam . Role ( this , 'notebookInstanceRole' , {
3947 roleName : "chemblOpenTargetsNotebookRole" ,
4048 assumedBy : new iam . ServicePrincipal ( 'sagemaker' )
4149 } ) ;
4250
51+ athenaSagingDirectory . grantReadWrite ( this . NotebookRole )
4352
4453 new sagemaker . CfnNotebookInstance ( this , 'analyticsNotebook' , {
4554 instanceType : 'ml.t2.medium' ,
4655 volumeSizeInGb : 100 ,
4756 securityGroupIds : [ notebookSg . securityGroupId ] ,
4857 subnetId : props . targetVpc . selectSubnets ( { subnetType : ec2 . SubnetType . PRIVATE } ) . subnetIds [ 0 ] ,
4958 notebookInstanceName : "Chembl-OpenTargets-Demo-Notebook" ,
50- roleArn : sageMakerInstanceRole . roleArn ,
59+ roleArn : this . NotebookRole . roleArn ,
5160 directInternetAccess : 'Disabled' ,
5261 lifecycleConfigName : sageMakerIntanceLifecyclePolicy . notebookInstanceLifecycleConfigName
5362 } ) ;
0 commit comments