Model

class aws_cdk.aws_sagemaker_alpha.Model(scope, id, *, allow_all_outbound=None, containers=None, model_name=None, role=None, security_groups=None, vpc=None, vpc_subnets=None)

Bases: Resource

(experimental) Defines a SageMaker Model.

Stability:

experimental

ExampleMetadata:

infused

Example:

import aws_cdk.aws_sagemaker_alpha as sagemaker
import path as path


image = sagemaker.ContainerImage.from_asset(path.join("path", "to", "Dockerfile", "directory"))
model_data = sagemaker.ModelData.from_asset(path.join("path", "to", "artifact", "file.tar.gz"))

model = sagemaker.Model(self, "PrimaryContainerModel",
    containers=[sagemaker.ContainerDefinition(
        image=image,
        model_data=model_data
    )
    ]
)
Parameters:
  • scope (Construct) –

  • id (str) –

  • allow_all_outbound (Optional[bool]) – (experimental) 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. Default: true

  • containers (Optional[Sequence[Union[ContainerDefinition, Dict[str, Any]]]]) – (experimental) Specifies the container definitions for this model, consisting of either a single primary container or an inference pipeline of multiple containers. Default: - none

  • model_name (Optional[str]) – (experimental) Name of the SageMaker Model. Default: - AWS CloudFormation generates a unique physical ID and uses that ID for the model’s name.

  • role (Optional[IRole]) – (experimental) The IAM role that the Amazon SageMaker service assumes. Default: - a new IAM role will be created with the AmazonSageMakerFullAccess policy attached.

  • security_groups (Optional[Sequence[ISecurityGroup]]) – (experimental) 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: - A security group will be automatically created if ‘vpc’ is supplied

  • vpc (Optional[IVpc]) – (experimental) The VPC to deploy model containers to. Default: - none

  • vpc_subnets (Union[SubnetSelection, Dict[str, Any], None]) – (experimental) The VPC subnets to use when deploying model containers. Default: - none

Stability:

experimental

Methods

add_container(*, image, container_hostname=None, environment=None, model_data=None)

(experimental) Add containers to the model.

Parameters:
  • image (ContainerImage) – (experimental) The image used to start a container.

  • container_hostname (Optional[str]) – (experimental) Hostname of the container within an inference pipeline. For single container models, this field is ignored. When specifying a hostname for one ContainerDefinition in a pipeline, hostnames must be specified for all other ContainerDefinitions in that pipeline. Default: - Amazon SageMaker will automatically assign a unique name based on the position of this ContainerDefinition in an inference pipeline.

  • environment (Optional[Mapping[str, str]]) – (experimental) A map of environment variables to pass into the container. Default: - none

  • model_data (Optional[ModelData]) – (experimental) S3 path to the model artifacts. Default: - none

Stability:

experimental

Return type:

None

add_to_role_policy(statement)

(experimental) Adds a statement to the IAM role assumed by the instance.

Parameters:

statement (PolicyStatement) –

Stability:

experimental

Return type:

None

apply_removal_policy(policy)

Apply the given removal policy to this resource.

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).

Parameters:

policy (RemovalPolicy) –

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

connections

(experimental) An accessor for the Connections object that will fail if this Model does not have a VPC configured.

Stability:

experimental

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

grant_principal

(experimental) The principal this Model is running as.

Stability:

experimental

model_arn

(experimental) Returns the ARN of this model.

Stability:

experimental

Attribute:

true

model_name

(experimental) Returns the name of the model.

Stability:

experimental

Attribute:

true

node

The tree node.

role

(experimental) Execution role for SageMaker Model.

Stability:

experimental

stack

The stack in which this resource is defined.

Static Methods

classmethod from_model_arn(scope, id, model_arn)

(experimental) Imports a Model defined either outside the CDK or in a different CDK stack.

Parameters:
  • scope (Construct) – the Construct scope.

  • id (str) – the resource id.

  • model_arn (str) – the ARN of the model.

Stability:

experimental

Return type:

IModel

classmethod from_model_attributes(scope, id, *, model_arn, role=None, security_groups=None)

(experimental) Imports a Model defined either outside the CDK or in a different CDK stack.

Parameters:
  • scope (Construct) – the Construct scope.

  • id (str) – the resource id.

  • model_arn (str) – (experimental) The ARN of this model.

  • role (Optional[IRole]) – (experimental) The IAM execution role associated with this model. Default: - When not provided, any role-related operations will no-op.

  • security_groups (Optional[Sequence[ISecurityGroup]]) – (experimental) The security groups for this model, if in a VPC. Default: - When not provided, the connections to/from this model cannot be managed.

Stability:

experimental

Return type:

IModel

classmethod from_model_name(scope, id, model_name)

(experimental) Imports a Model defined either outside the CDK or in a different CDK stack.

Parameters:
  • scope (Construct) – the Construct scope.

  • id (str) – the resource id.

  • model_name (str) – the name of the model.

Stability:

experimental

Return type:

IModel

classmethod is_construct(x)

Checks if x is a construct.

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:

x (Any) – Any object.

Return type:

bool

Returns:

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

classmethod is_owned_resource(construct)

Returns true if the construct was created by CDK, and false otherwise.

Parameters:

construct (IConstruct) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool