AWS::SageMaker::Model - AWS CloudFormation
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

AWS::SageMaker::Model

AWS::SageMaker::Model 资源可用于创建在 Amazon SageMaker 终端节点上托管的模型。有关更多信息,请参阅 Amazon SageMaker 开发人员指南 中的在 Amazon SageMaker 托管服务上部署模型

语法

要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:

JSON

{ "Type" : "AWS::SageMaker::Model", "Properties" : { "Containers" : [ ContainerDefinition, ... ], "ExecutionRoleArn" : String, "ModelName" : String, "PrimaryContainer" : ContainerDefinition, "Tags" : [ Tag, ... ], "VpcConfig" : VpcConfig } }

YAML

Type: AWS::SageMaker::Model Properties: Containers: - ContainerDefinition ExecutionRoleArn: String ModelName: String PrimaryContainer: ContainerDefinition Tags: - Tag VpcConfig: VpcConfig

属性

Containers

指定推理管道中的容器。

必需:否

类型ContainerDefinition 的列表

最高5

Update requires: Replacement

ExecutionRoleArn

IAM 角色的 Amazon 资源名称 (ARN),Amazon SageMaker 可代入此角色以访问用于 ML 计算实例上的部署或批量转换作业的模型构件和 Docker 映像。在 ML 计算实例上部署是模型托管的一部分。有关更多信息,请参阅 Amazon SageMaker 角色

注意

要能够将此角色传递给 Amazon SageMaker,此 API 的调用方必须具有 iam:PassRole 权限。

必需:是

类型:字符串

最低20

最高2048

模式^arn:aws[a-z\-]*:iam::\d{12}:role/?[a-zA-Z_0-9+=,.@\-_/]+$

Update requires: Replacement

ModelName

新模型的名称。

必需:否

类型:字符串

最高63

模式^[a-zA-Z0-9](-*[a-zA-Z0-9])*

Update requires: Replacement

PrimaryContainer

主要 Docker 映像的位置,该映像包含推理代码、关联构件和自定义环境贴图(在部署模型以进行预测时,推理代码将使用此贴图)。

必需:否

类型ContainerDefinition

Update requires: Replacement

Tags

要应用于此资源的键/值对的列表。

有关更多信息,请参阅 AWS 账单和成本管理用户指南 中的资源标签使用成本分配标签

必需:否

类型Tag 的列表

最高50

Update requires: No interruption

VpcConfig

一个 VpcConfig 对象,此对象指定您希望模型连接到的 VPC。通过配置 VPC 来控制对模型容器的访问以及来自模型容器的访问。VpcConfig 用于托管服务和批量转换中。有关更多信息,请参阅使用 Amazon Virtual Private Cloud 保护终端节点使用 Amazon Virtual Private Cloud 保护批量转换作业中的数据

必需:否

类型VpcConfig

Update requires: Replacement

返回值

Ref

在将此资源的逻辑 ID 传递给内部 Ref 函数时,Ref 返回模型的 Amazon 资源名称 (ARN),例如 arn:aws:sagemaker:us-west-2:012345678901:model/mymodel

如果将 AWS::SageMaker::Model 资源的逻辑 ID 传递给内部函数 Ref,则此函数将返回模型的 Amazon 资源名称 (ARN),如 arn:aws:sagemaker:us-west-2:012345678901:model/mymodel

For more information about using the Ref function, see Ref.

Fn::GetAtt

Fn::GetAtt 内部函数返回此类型的一个指定属性的值。以下为可用属性和示例返回值。

有关使用 Fn::GetAtt 内部函数的更多信息,请参阅 Fn::GetAtt

Fn::GetAtt 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

ModelName

模型的名称,例如 MyModel

示例

SageMaker 模型终端节点示例

以下示例从训练后的模型创建终端节点配置,然后创建一个终端节点。

JSON

{ "Description": "Basic Hosting entities test. We need models to create endpoint configs.", "Mappings": { "RegionMap": { "us-west-2": { "NullTransformer": "12345678901.dkr.ecr.us-west-2.amazonaws.com/mymodel:latest" }, "us-east-2": { "NullTransformer": "12345678901.dkr.ecr.us-east-2.amazonaws.com/mymodel:latest" }, "us-east-1": { "NullTransformer": "12345678901.dkr.ecr.us-east-1.amazonaws.com/mymodel:latest" }, "eu-west-1": { "NullTransformer": "12345678901.dkr.ecr.eu-west-1.amazonaws.com/mymodel:latest" }, "ap-northeast-1": { "NullTransformer": "12345678901.dkr.ecr.ap-northeast-1.amazonaws.com/mymodel:latest" }, "ap-northeast-2": { "NullTransformer": "12345678901.dkr.ecr.ap-northeast-2.amazonaws.com/mymodel:latest" }, "ap-southeast-2": { "NullTransformer": "12345678901.dkr.ecr.ap-southeast-2.amazonaws.com/mymodel:latest" }, "eu-central-1": { "NullTransformer": "12345678901.dkr.ecr.eu-central-1.amazonaws.com/mymodel:latest" } } }, "Resources": { "Endpoint": { "Type": "AWS::SageMaker::Endpoint", "Properties": { "EndpointConfigName": { "Fn::GetAtt" : ["EndpointConfig", "EndpointConfigName" ] } } }, "EndpointConfig": { "Type": "AWS::SageMaker::EndpointConfig", "Properties": { "ProductionVariants": [ { "InitialInstanceCount": 1, "InitialVariantWeight": 1, "InstanceType": "ml.t2.large", "ModelName": { "Fn::GetAtt" : ["Model", "ModelName" ] }, "VariantName": { "Fn::GetAtt" : ["Model", "ModelName" ] } } ] } }, "Model": { "Type": "AWS::SageMaker::Model", "Properties": { "PrimaryContainer": { "Image": { "Fn::FindInMap" : [ "AWS::Region", "NullTransformer"] } }, "ExecutionRoleArn": { "Fn::GetAtt" : [ "ExecutionRole", "Arn" ] } } }, "ExecutionRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "sagemaker.amazonaws.com" ] }, "Action": [ "sts:AssumeRole" ] } ] }, "Path": "/", "Policies": [ { "PolicyName": "root", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "*", "Resource": "*" } ] } } ] } } }, "Outputs": { "EndpointId": { "Value": { "Ref" : "Endpoint" } }, "EndpointName": { "Value": { "Fn::GetAtt" : [ "Endpoint", "EndpointName" ] } } } }

YAML

Description: "Basic Hosting entities test. We need models to create endpoint configs." Mappings: RegionMap: "us-west-2": "NullTransformer": "123456789012.dkr.ecr.us-west-2.amazonaws.com/mymodel:latest" "us-east-2": "NullTransformer": "123456789012.dkr.ecr.us-east-2.amazonaws.com/mymodel:latest" "us-east-1": "NullTransformer": "123456789012.dkr.ecr.us-east-1.amazonaws.com/mymodel:latest" "eu-west-1": "NullTransformer": "123456789012.dkr.ecr.eu-west-1.amazonaws.com/mymodel:latest" "ap-northeast-1": "NullTransformer": "123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/mymodel:latest" "ap-northeast-2": "NullTransformer": "123456789012.dkr.ecr.ap-northeast-2.amazonaws.com/mymodel:latest" "ap-southeast-2": "NullTransformer": "123456789012.dkr.ecr.ap-southeast-2.amazonaws.com/mymodel:latest" "eu-central-1": "NullTransformer": "123456789012.dkr.ecr.eu-central-1.amazonaws.com/mymodel:latest" Resources: Endpoint: Type: "AWS::SageMaker::Endpoint" Properties: EndpointConfigName: !GetAtt EndpointConfig.EndpointConfigName EndpointConfig: Type: "AWS::SageMaker::EndpointConfig" Properties: ProductionVariants: - InitialInstanceCount: 1 InitialVariantWeight: 1.0 InstanceType: ml.t2.large ModelName: !GetAtt Model.ModelName VariantName: !GetAtt Model.ModelName Model: Type: "AWS::SageMaker::Model" Properties: PrimaryContainer: Image: !FindInMap [RegionMap, !Ref "AWS::Region", "NullTransformer"] ExecutionRoleArn: !GetAtt ExecutionRole.Arn ExecutionRole: Type: "AWS::IAM::Role" Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Principal: Service: - "sagemaker.amazonaws.com" Action: - "sts:AssumeRole" Path: "/" Policies: - PolicyName: "root" PolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Action: "*" Resource: "*" Outputs: EndpointId: Value: !Ref Endpoint EndpointName: Value: !GetAtt Endpoint.EndpointName