|
| 1 | +AWSTemplateFormatVersion: 2010-09-09 |
| 2 | +Description: >- |
| 3 | + (SO0056) - fraud-detection-using-machine-learning: Notebook instance stack |
| 4 | +Parameters: |
| 5 | + SolutionPrefix: |
| 6 | + Type: String |
| 7 | + Default: "sm-soln-fraud-detection" |
| 8 | + ParentStackName: |
| 9 | + Type: String |
| 10 | + SolutionName: |
| 11 | + Type: String |
| 12 | + StackVersion: |
| 13 | + Type: String |
| 14 | + ModelDataBucket: |
| 15 | + Type: String |
| 16 | + NotebookInstanceExecutionRoleArn: |
| 17 | + Type: String |
| 18 | + RESTAPIGateway: |
| 19 | + Type: String |
| 20 | + |
| 21 | +Mappings: |
| 22 | + SolutionsS3BucketName: |
| 23 | + development: |
| 24 | + Prefix: sagemaker-solutions-build |
| 25 | + release: |
| 26 | + Prefix: sagemaker-solutions |
| 27 | + |
| 28 | +Resources: |
| 29 | + BasicNotebookInstance: |
| 30 | + Type: 'AWS::SageMaker::NotebookInstance' |
| 31 | + Properties: |
| 32 | + InstanceType: ml.t3.medium |
| 33 | + NotebookInstanceName: !Sub "${SolutionPrefix}-notebook-instance" |
| 34 | + RoleArn: !Ref NotebookInstanceExecutionRoleArn |
| 35 | + LifecycleConfigName: !GetAtt |
| 36 | + - BasicNotebookInstanceLifecycleConfig |
| 37 | + - NotebookInstanceLifecycleConfigName |
| 38 | + Metadata: |
| 39 | + cfn_nag: |
| 40 | + rules_to_suppress: |
| 41 | + - id: W1201 |
| 42 | + reason: Solution does not have KMS encryption enabled by default |
| 43 | + |
| 44 | + BasicNotebookInstanceLifecycleConfig: |
| 45 | + Type: 'AWS::SageMaker::NotebookInstanceLifecycleConfig' |
| 46 | + Properties: |
| 47 | + NotebookInstanceLifecycleConfigName: !Sub "${SolutionPrefix}-nb-lifecycle-config" |
| 48 | + OnCreate: |
| 49 | + - Content: |
| 50 | + Fn::Base64: !Sub |
| 51 | + - | |
| 52 | + set -e |
| 53 | + # perform following actions as ec2-user |
| 54 | + sudo -u ec2-user -i <<EOF |
| 55 | + cd /home/ec2-user/SageMaker |
| 56 | + # copy source files |
| 57 | + aws s3 sync s3://${SolutionsS3BucketNamePrefix}-${AWS::Region}/${SolutionName}/ . |
| 58 | + unzip creditcardfraud.zip -d ./source/notebooks/ |
| 59 | + # create stack_outputs.json with stack resources that are required in notebook(s) |
| 60 | + touch stack_outputs.json |
| 61 | + echo '{' >> stack_outputs.json |
| 62 | + echo ' "FraudStackName": "${ParentStackName}",' >> stack_outputs.json |
| 63 | + echo ' "SolutionPrefix": "${SolutionPrefix}",' >> stack_outputs.json |
| 64 | + echo ' "AwsAccountId": "${AWS::AccountId}",' >> stack_outputs.json |
| 65 | + echo ' "AwsRegion": "${AWS::Region}",' >> stack_outputs.json |
| 66 | + echo ' "IamRole": "${NotebookInstanceExecutionRoleArn}",' >> stack_outputs.json |
| 67 | + echo ' "ModelDataBucket": "${ModelDataBucket}",' >> stack_outputs.json |
| 68 | + echo ' "SolutionsS3Bucket": "${SolutionsS3BucketNamePrefix}-${AWS::Region}",' >> stack_outputs.json |
| 69 | + echo ' "RESTAPIGateway": "${RESTAPIGateway}",' >> stack_outputs.json |
| 70 | + echo ' "SagemakerMode": "NotebookInstance"' >> stack_outputs.json |
| 71 | + echo '}' >> stack_outputs.json |
| 72 | + echo "stack_outputs.json created:" |
| 73 | + cat stack_outputs.json |
| 74 | + EOF |
| 75 | + - SolutionsS3BucketNamePrefix: |
| 76 | + Fn::FindInMap: [SolutionsS3BucketName, Ref: StackVersion, Prefix] |
| 77 | + OnStart: |
| 78 | + - Content: |
| 79 | + Fn::Base64: | |
| 80 | + set -e |
| 81 | + # perform following actions as ec2-user |
| 82 | + sudo -u ec2-user -i <<EOF |
| 83 | + /home/ec2-user/anaconda3/envs/python3/bin/python /home/ec2-user/SageMaker/source/env_setup.py --force --log-level DEBUG |
| 84 | + EOF |
| 85 | +Outputs: |
| 86 | + SageMakerNotebook: |
| 87 | + Description: "Opens the Jupyter notebook to get started with model training" |
| 88 | + Value: !Sub "https://${SolutionPrefix}-notebook-instance.notebook.${AWS::Region}.sagemaker.aws/notebooks/source/notebooks/sagemaker_fraud_detection.ipynb" |
0 commit comments