Skip to content
v2.273.0

Experimental

@aws-cdk/aws-sagemaker-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

Model L2 construct ​

Defines a SageMaker Model.

Example ​

ts
import * as sagemaker from '@aws-cdk/aws-sagemaker-alpha';

declare const image: sagemaker.ContainerImage;
declare const modelData: sagemaker.ModelData;

const model = new sagemaker.Model(this, 'ContainerModel', {
  containers: [
    {
      image,
      modelData,
    }
  ],
  networkIsolation: true,
});
python
import aws_cdk.aws_sagemaker_alpha as sagemaker

# image: sagemaker.ContainerImage
# model_data: sagemaker.ModelData


model = sagemaker.Model(self, "ContainerModel",
    containers=[sagemaker.ContainerDefinition(
        image=image,
        model_data=model_data
    )
    ],
    network_isolation=True
)
java
import software.amazon.awscdk.services.sagemaker.alpha.*;

ContainerImage image;
ModelData modelData;


Model model = Model.Builder.create(this, "ContainerModel")
        .containers(List.of(ContainerDefinition.builder()
                .image(image)
                .modelData(modelData)
                .build()))
        .networkIsolation(true)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.Sagemaker.Alpha
using Amazon.CDK.AWS.Sagemaker.Alpha;

ContainerImage image;
ModelData modelData;


var model = new Model(this, "ContainerModel", new ModelProps {
    Containers = new [] { new ContainerDefinition {
        Image = image,
        ModelData = modelData
    } },
    NetworkIsolation = true
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdksagemakeralpha/v2
import sagemaker "github.com/aws/aws-cdk-go/awscdksagemakeralpha"

var image ContainerImage
var modelData ModelData


model := sagemaker.NewModel(this, jsii.String("ContainerModel"), &ModelProps{
	Containers: []ContainerDefinition{
		&ContainerDefinition{
			Image: *Image,
			ModelData: *ModelData,
		},
	},
	NetworkIsolation: jsii.Boolean(true),
})

Initializer ​

ts
new Model(scope: Construct, id: string, props?: ModelProps)
python
Model(scope: Construct, id: str, props: typing.Optional[ModelProps] = None)
java
new Model(Construct scope, String id, ModelProps props)
csharp
new Model(Construct scope, string id, ModelProps? props = null)
go
NewModel(Scope Construct, Id *string, Props ModelProps)

Construct Props ​

allowAllOutboundbooleanallow_all_outboundboolallowAllOutboundBooleanAllowAllOutboundboolAllowAllOutbound*bool= true#
Whether to allow the SageMaker Model to send all network traffic.

If set to false, you must individually add traffic rules to allow the SageMaker Model to connect to network targets.

Only used if 'vpc' is supplied.

containersContainerDefinition[]containerstyping.List[ContainerDefinition]containersList<ContainerDefinition>ContainersContainerDefinition[]Containers*[]ContainerDefinition= none#
Specifies the container definitions for this model, consisting of either a single primary container or an inference pipeline of multiple containers.
modelNamestringmodel_namestrmodelNameStringModelNamestringModelName*string= AWS CloudFormation generates a u…#
Name of the SageMaker Model.
default

Default: AWS CloudFormation generates a unique physical ID and uses that ID for the model's name.

networkIsolationbooleannetwork_isolationboolnetworkIsolationBooleanNetworkIsolationboolNetworkIsolation*bool= false#
Whether to enable network isolation for the model container.

When enabled, no inbound or outbound network calls can be made to or from the model container.

roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRole= a new IAM role will be created w…#
The IAM role that the Amazon SageMaker service assumes.
default

Default: a new IAM role will be created with the AmazonSageMakerFullAccess policy attached.

securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGroup= A security group will be automat…#
The security groups to associate to the Model.

If no security groups are provided and 'vpc' is configured, one security group will be created automatically.

default

Default: A security group will be automatically created if 'vpc' is supplied

vpcIVpcvpcIVpcvpcIVpcVpcIVpcVpcIVpc= none#
The VPC to deploy model containers to.
vpcSubnetsSubnetSelectionvpc_subnetsSubnetSelectionvpcSubnetsSubnetSelectionVpcSubnetsSubnetSelectionVpcSubnetsSubnetSelection= none#
The VPC subnets to use when deploying model containers.

Properties ​

connectionsConnectionsconnectionsConnectionsconnectionsConnectionsConnectionsConnectionsConnectionsConnectionsrequired#
An accessor for the Connections object that will fail if this Model does not have a VPC configured.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipalrequired#
The principal this Model is running as.
modelArnstringmodel_arnstrmodelArnStringModelArnstringModelArn*stringrequired#
Returns the ARN of this model.
modelNamestringmodel_namestrmodelNameStringModelNamestringModelName*stringrequired#
Returns the name of the model.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRole#
Execution role for SageMaker Model.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.

Methods ​

addContainer(container: ContainerDefinition): voiddef add_container(self, container: ContainerDefinition) -> Nonepublic void addContainer(ContainerDefinition container)public void AddContainer(ContainerDefinition container)func AddContainer(Container ContainerDefinition)#
Add containers to the model.
1 parameter

Parameters

  • containercontainercontainercontainerContainer — The container definition to add.
addToRolePolicy(statement: PolicyStatement): voiddef add_to_role_policy(self, statement: PolicyStatement) -> Nonepublic void addToRolePolicy(PolicyStatement statement)public void AddToRolePolicy(PolicyStatement statement)func AddToRolePolicy(Statement PolicyStatement)#
Adds a statement to the IAM role assumed by the instance.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromModelArn(scope: Construct, id: string, modelArn: string): IModel@staticmethod def from_model_arn(scope: Construct, id: str, model_arn: str) -> IModelpublic static IModel fromModelArn(Construct scope, String id, String modelArn)public static IModel FromModelArn(Construct scope, string id, string modelArn)func FromModelArn(Scope Construct, Id *string, ModelArn *string) IModelstatic#
Imports a Model defined either outside the CDK or in a different CDK stack.
3 parameters

Parameters

  • scopescopescopescopeScope — the Construct scope.
  • ididididId — the resource id.
  • modelArnmodel_arnmodelArnmodelArnModelArn — the ARN of the model.
fromModelAttributes(scope: Construct, id: string, attrs: ModelAttributes): IModel@staticmethod def from_model_attributes(scope: Construct, id: str, attrs: ModelAttributes) -> IModelpublic static IModel fromModelAttributes(Construct scope, String id, ModelAttributes attrs)public static IModel FromModelAttributes(Construct scope, string id, ModelAttributes attrs)func FromModelAttributes(Scope Construct, Id *string, Attrs ModelAttributes) IModelstatic#
Imports a Model defined either outside the CDK or in a different CDK stack.
3 parameters

Parameters

  • scopescopescopescopeScope — the Construct scope.
  • ididididId — the resource id.
  • attrsattrsattrsattrsAttrs — the attributes of the model to import.
fromModelName(scope: Construct, id: string, modelName: string): IModel@staticmethod def from_model_name(scope: Construct, id: str, model_name: str) -> IModelpublic static IModel fromModelName(Construct scope, String id, String modelName)public static IModel FromModelName(Construct scope, string id, string modelName)func FromModelName(Scope Construct, Id *string, ModelName *string) IModelstatic#
Imports a Model defined either outside the CDK or in a different CDK stack.
3 parameters

Parameters

  • scopescopescopescopeScope — the Construct scope.
  • ididididId — the resource id.
  • modelNamemodel_namemodelNamemodelNameModelName — the name of the model.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.