MCPcopy Create free account
hub / github.com/aws-samples/aws-cdk-examples / NewNotebookStack

Function NewNotebookStack

go/sagemaker/notebook/notebook.go:19–65  ·  view source on GitHub ↗
(scope constructs.Construct, id string, props *NotebookStackProps)

Source from the content-addressed store, hash-verified

17}
18
19func NewNotebookStack(scope constructs.Construct, id string, props *NotebookStackProps) awscdk.Stack {
20 var sprops awscdk.StackProps
21 if props != nil {
22 sprops = props.StackProps
23 }
24 stack := awscdk.NewStack(scope, &id, &sprops)
25
26 // Create an IAM role for the SageMaker notebook
27 serviceRole := awsiam.NewRole(stack, jsii.String("SageMakerNotebookRole"),
28 &awsiam.RoleProps{
29 AssumedBy: awsiam.NewServicePrincipal(jsii.String("sagemaker.amazonaws.com"), nil),
30 Description: jsii.String("Role for SageMaker notebook"),
31 })
32
33 // Add permissions to assume role and write logs to CloudWatch.
34 serviceRole.AddToPolicy(awsiam.NewPolicyStatement(&awsiam.PolicyStatementProps{
35 Actions: &[]*string{
36 jsii.String("sts:AssumeRole"),
37 jsii.String("logs:DescribeLogStreams"),
38 jsii.String("logs:CreateLogStream"),
39 jsii.String("logs:CreateLogGroup"),
40 jsii.String("logs:PutLogEvents"),
41 },
42 Resources: &[]*string{
43 jsii.String("*"),
44 },
45 }))
46
47 // Define the SageMaker notebook instance with the specified parameters.
48 notebook := awssagemaker.NewCfnNotebookInstance(
49 stack, jsii.String("MyNotebookInstance"), &awssagemaker.CfnNotebookInstanceProps{
50 InstanceType: props.InstanceType,
51 RoleArn: serviceRole.RoleArn(),
52 NotebookInstanceName: props.NotebookName,
53 VolumeSizeInGb: props.VolumeSizeInGb,
54 DirectInternetAccess: jsii.String("Enabled"),
55 RootAccess: jsii.String("Disabled"),
56 })
57
58 // Add the Notebook instance name as CloudFormation output.
59 awscdk.NewCfnOutput(stack, jsii.String("NotebookInstanceName"),
60 &awscdk.CfnOutputProps{
61 Value: notebook.NotebookInstanceName(),
62 })
63
64 return stack
65}
66
67func main() {
68 defer jsii.Close()

Callers 2

TestNotebookStackFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestNotebookStackFunction · 0.68