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

AWS::SageMaker::NotebookInstanceLifecycleConfig

AWS::SageMaker::NotebookInstanceLifecycleConfig 资源创建在您创建和/或启动笔记本实例时运行的 Shell 脚本。有关笔记本实例生命周期配置的信息,请参阅 Amazon SageMaker 开发人员指南 中的自定义笔记本实例

语法

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

JSON

{ "Type" : "AWS::SageMaker::NotebookInstanceLifecycleConfig", "Properties" : { "NotebookInstanceLifecycleConfigName" : String, "OnCreate" : [ NotebookInstanceLifecycleHook, ... ], "OnStart" : [ NotebookInstanceLifecycleHook, ... ] } }

YAML

Type: AWS::SageMaker::NotebookInstanceLifecycleConfig Properties: NotebookInstanceLifecycleConfigName: String OnCreate: - NotebookInstanceLifecycleHook OnStart: - NotebookInstanceLifecycleHook

属性

NotebookInstanceLifecycleConfigName

生命周期配置的名称。

必需:否

类型:字符串

最高63

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

Update requires: Replacement

OnCreate

一个 Shell 脚本,它在您创建笔记本实例时仅运行一次。此 shell 脚本必须是 base64 编码的字符串。

必需:否

类型NotebookInstanceLifecycleHook 的列表

最高1

Update requires: No interruption

OnStart

一个 Shell 脚本,每当您启动笔记本实例时(包括在您创建笔记本实例时),此脚本将运行。此 shell 脚本必须是 base64 编码的字符串。

必需:否

类型NotebookInstanceLifecycleHook 的列表

最高1

Update requires: No interruption

返回值

Ref

在将此资源的逻辑 ID 传递给内部 Ref 函数时,Ref 返回终端节点配置的 Amazon 资源名称 (ARN),例如 arn:aws:sagemaker:us-west-2:012345678901:notebook-instance-lifecycle-config/mylifecycleconfig

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

Fn::GetAtt

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

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

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

NotebookInstanceLifecycleConfigName

生命周期配置的名称,例如 MyLifecycleConfig

示例

SageMaker NotebookInstanceLifecycleConfig 示例

以下示例创建一个具有关联的生命周期配置的笔记本实例。

JSON

{ "Description": "Basic NotebookInstance test", "Resources": { "BasicNotebookInstance": { "Type": "AWS::SageMaker::NotebookInstance", "Properties": { "InstanceType": "ml.t2.medium", "RoleArn": { "Fn::GetAtt" : [ "ExecutionRole", "Arn" ] }, "LifecycleConfigName": { "Fn::GetAtt" : [ "BasicNotebookInstanceLifecycleConfig", "NotebookInstanceLifecycleConfigName" ] } }, "BasicNotebookInstanceLifecycleConfig": { "Type": "AWS::SageMaker::NotebookInstanceLifecycleConfig", "Properties": { "OnStart": [ { "Content": { "Fn::Base64": "echo 'hello'" } } ] } }, "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": { "BasicNotebookInstanceId": { "Value": { "Ref" : "BasicNotebookInstance" } }, "BasicNotebookInstanceLifecycleConfigId": { "Value": { "Ref" : "BasicNotebookInstanceLifecycleConfig" } } }, }

YAML

Description: "Basic NotebookInstance test" Resources: BasicNotebookInstance: Type: "AWS::SageMaker::NotebookInstance" Properties: InstanceType: "ml.t2.medium" RoleArn: !GetAtt ExecutionRole.Arn LifecycleConfigName: !GetAtt BasicNotebookInstanceLifecycleConfig.NotebookInstanceLifecycleConfigName BasicNotebookInstanceLifecycleConfig: Type: "AWS::SageMaker::NotebookInstanceLifecycleConfig" Properties: OnStart: - Content: Fn::Base64: "echo 'hello'" 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: BasicNotebookInstanceId: Value: !Ref BasicNotebookInstance BasicNotebookInstanceLifecycleConfigId: Value: !Ref BasicNotebookInstanceLifecycleConfig