A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Amazon SageMaker is a fully managed machine learning service that enables developers and data scientists to build, train, and deploy ML models quickly.
import * as aws from "@pulumi/aws";
import * as sagemaker from "@pulumi/aws/sagemaker";Jupyter notebook environment for ML development.
const notebookInstance = new aws.sagemaker.NotebookInstance("ml-notebook", {
name: "my-ml-notebook",
roleArn: sagemakerRole.arn,
instanceType: "ml.t3.medium",
volumeSizeInGb: 20,
directInternetAccess: "Enabled",
tags: {
Environment: "development",
},
});Define a trained ML model.
const model = new aws.sagemaker.Model("prediction-model", {
name: "my-prediction-model",
executionRoleArn: sagemakerRole.arn,
primaryContainer: {
image: "12345678.dkr.ecr.us-west-2.amazonaws.com/my-model:latest",
modelDataUrl: pulumi.interpolate`s3://${modelBucket.id}/model.tar.gz`,
},
tags: {
Model: "prediction",
},
});Configuration for model endpoint.
const endpointConfig = new aws.sagemaker.EndpointConfiguration("endpoint-config", {
name: "my-endpoint-config",
productionVariants: [{
variantName: "default",
modelName: model.name,
initialInstanceCount: 1,
instanceType: "ml.t2.medium",
}],
tags: {
Environment: "production",
},
});Deploy model for inference.
const endpoint = new aws.sagemaker.Endpoint("inference-endpoint", {
name: "my-inference-endpoint",
endpointConfigName: endpointConfig.name,
tags: {
Application: "ml-inference",
},
});const trainingJob = new aws.sagemaker.TrainingJob("training", {
name: "model-training-job",
roleArn: sagemakerRole.arn,
algorithmSpecification: {
trainingImage: "12345678.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest",
trainingInputMode: "File",
},
inputDataConfig: [{
channelName: "training",
dataSource: {
s3DataSource: {
s3DataType: "S3Prefix",
s3Uri: pulumi.interpolate`s3://${dataBucket.id}/training/`,
s3DataDistributionType: "FullyReplicated",
},
},
contentType: "text/csv",
}],
outputDataConfig: {
s3OutputPath: pulumi.interpolate`s3://${modelBucket.id}/output/`,
},
resourceConfig: {
instanceType: "ml.m5.xlarge",
instanceCount: 1,
volumeSizeInGb: 50,
},
stoppingCondition: {
maxRuntimeInSeconds: 3600,
},
hyperParameters: {
max_depth: "5",
eta: "0.2",
objective: "binary:logistic",
num_round: "100",
},
});const autoMLJob = new aws.sagemaker.AutoMLJob("automl", {
name: "automl-job",
roleArn: sagemakerRole.arn,
inputDataConfig: [{
dataSource: {
s3DataSource: {
s3DataType: "S3Prefix",
s3Uri: pulumi.interpolate`s3://${dataBucket.id}/input/`,
},
},
targetAttributeName: "target",
}],
outputDataConfig: {
s3OutputPath: pulumi.interpolate`s3://${outputBucket.id}/automl/`,
},
problemType: "BinaryClassification",
autoMLJobObjective: {
metricName: "F1",
},
});const multiModelEndpointConfig = new aws.sagemaker.EndpointConfiguration("multi-model", {
name: "multi-model-config",
productionVariants: [{
variantName: "default",
modelName: model.name,
initialInstanceCount: 1,
instanceType: "ml.m5.xlarge",
}],
});
const multiModel = new aws.sagemaker.Model("multi-model", {
name: "multi-model-endpoint",
executionRoleArn: sagemakerRole.arn,
primaryContainer: {
image: "12345678.dkr.ecr.us-west-2.amazonaws.com/multi-model:latest",
mode: "MultiModel",
modelDataUrl: pulumi.interpolate`s3://${modelBucket.id}/models/`,
},
});const vpcModel = new aws.sagemaker.Model("vpc-model", {
name: "vpc-model",
executionRoleArn: sagemakerRole.arn,
primaryContainer: {
image: "12345678.dkr.ecr.us-west-2.amazonaws.com/model:latest",
modelDataUrl: pulumi.interpolate`s3://${modelBucket.id}/model.tar.gz`,
},
vpcConfig: {
subnets: subnetIds,
securityGroupIds: [securityGroup.id],
},
});name - Notebook instance nameroleArn - IAM role ARNinstanceType - Instance type (ml.t3.medium, etc.)volumeSizeInGb - EBS volume sizename - Model nameexecutionRoleArn - IAM role ARNprimaryContainer - Container image and model datavpcConfig - VPC configuration for private inferencename - Endpoint nameendpointConfigName - Configuration nametags - Resource tagsid - Resource identifierarn - Resource ARNname - Resource nameInstall with Tessl CLI
npx tessl i tessl/npm-pulumi--aws