Skip to content

jorge-ortega/sagemaker-notebook-cdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SageMaker Notebook CDK Template

This project provides a CDK template that provisions a SageMaker notebook instance with configurable properties.

Architecture

The template creates the following AWS resources:

  • SageMaker Notebook Instance: A managed Jupyter notebook environment
  • IAM Role: Service role for the notebook instance with appropriate permissions

Features

  • Configurable Instance Type: Choose the compute capacity (default: ml.t3.medium)
  • Configurable Storage: Set the volume size in GB (default: 5 GB)
  • Secure Setup: Includes proper IAM role with SageMaker permissions
  • Cost Optimized: Uses inexpensive instance types by default

Configuration

The stack accepts the following properties:

interface SageMakerNotebookStackProps {
  instanceType?: string;     // Default: 'ml.t3.medium'
  volumeSizeInGB?: number;   // Default: 5
}

Example Usage

import { SageMakerNotebookStack } from './lib/sagemaker-notebook-stack';

// Default configuration
new SageMakerNotebookStack(app, 'MyNotebookStack');

// Custom configuration
new SageMakerNotebookStack(app, 'MyNotebookStack', {
  instanceType: 'ml.t3.large',
  volumeSizeInGB: 20
});

Available Instance Types

Common SageMaker notebook instance types:

  • ml.t3.medium (2 vCPU, 4 GB RAM) - Default, cost-effective
  • ml.t3.large (2 vCPU, 8 GB RAM)
  • ml.t3.xlarge (4 vCPU, 16 GB RAM)
  • ml.m5.large (2 vCPU, 8 GB RAM)
  • ml.m5.xlarge (4 vCPU, 16 GB RAM)

Setup and Deployment

Prerequisites

  • Node.js 18+ installed
  • AWS CLI configured with appropriate credentials
  • CDK bootstrapped in your target AWS account/region

Installation

npm install

Build

npm run build

Test

npm test

Deploy

# Synthesize CloudFormation template
npm run synth

# Deploy the stack
npm run deploy

# View diff against deployed stack
npm run diff

# Destroy the stack
npm run destroy

Testing

The project includes comprehensive tests that verify:

  • ✅ SageMaker notebook instance creation with default configuration
  • ✅ SageMaker notebook instance creation with custom configuration
  • ✅ IAM role creation with proper trust policy and permissions
  • ✅ Correct resource counts (exactly one instance and one role)
  • ✅ Proper CloudFormation outputs
  • ✅ Instance type configurability
  • ✅ Volume size configurability
  • ✅ Proper resource references between components

Run tests with:

npm test

Outputs

The stack provides the following outputs:

  • NotebookInstanceArn: ARN of the created SageMaker notebook instance
  • NotebookInstanceName: Name of the notebook instance
  • NotebookRoleArn: ARN of the IAM role used by the notebook instance

Cost Considerations

  • Default instance type (ml.t3.medium) is cost-effective for development and light workloads
  • Default storage volume (5 GB) is minimal to keep costs low
  • Remember to stop or delete the notebook instance when not in use to avoid charges

Security

The IAM role created for the notebook instance includes:

  • Trust policy allowing SageMaker service to assume the role
  • AmazonSageMakerFullAccess managed policy for SageMaker operations

For production use, consider implementing more restrictive IAM policies based on your specific requirements.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published