This project provides a CDK template that provisions a SageMaker notebook instance with configurable properties.
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
- 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
The stack accepts the following properties:
interface SageMakerNotebookStackProps {
instanceType?: string; // Default: 'ml.t3.medium'
volumeSizeInGB?: number; // Default: 5
}
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
});
Common SageMaker notebook instance types:
ml.t3.medium
(2 vCPU, 4 GB RAM) - Default, cost-effectiveml.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)
- Node.js 18+ installed
- AWS CLI configured with appropriate credentials
- CDK bootstrapped in your target AWS account/region
npm install
npm run build
npm test
# 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
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
The stack provides the following outputs:
NotebookInstanceArn
: ARN of the created SageMaker notebook instanceNotebookInstanceName
: Name of the notebook instanceNotebookRoleArn
: ARN of the IAM role used by the notebook instance
- 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
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.