【问题标题】:How to upload files in with a Sagemaker notebook instance created through AWS cloud formation template如何使用通过 AWS 云形成模板创建的 Sagemaker 笔记本实例上传文件
【发布时间】:2021-06-03 01:28:59
【问题描述】:

我正在创建一个 AWS 云形成堆栈,其中我们通过模板创建资源。 yaml 并在项目文件中为该资源创建文件夹,以指示创建后该资源中的所有文件。

例如,我在模板中创建了一个 lambda 函数。 yaml 的名称 - “count_calories” 并在项目文件中创建一个文件夹 - “count_calories” 并在其中放置一个带有 lambda 处理程序和要求的 py 文件。 txt 文件。

以类似的方式,现在我必须通过 template.yaml 创建一个 sagemaker 笔记本实例,然后在该笔记本实例中上传 jupyter 笔记本,每次使用该云形成模板创建堆栈时。

我使用以下模板代码创建了 sagemaker 笔记本实例:


 NotebookInstance: #Sagemaker notebook instance 
    Type: AWS::SageMaker::NotebookInstance
    Properties: 
      InstanceType: ml.t3.medium
      NotebookInstanceName: !Sub Calorie-NotebookInstance-${EnvVar}
      RoleArn: <RoleARN>
      RootAccess: Enabled
      VolumeSizeInGB: 200

我有 4 个 Jupyter 笔记本和一个数据文件,一旦创建,它就应该进入这个笔记本实例。我想通过代码上传,而不是从 AWS 控制台上传。请向我建议正确的方法或指出我可以遵循的任何示例。

非常感谢

【问题讨论】:

    标签: amazon-web-services jupyter-notebook amazon-sagemaker aws-sam aws-cloudformation-custom-resource


    【解决方案1】:

    使用模板Type: AWS::SageMaker::NotebookInstance,您走在正确的道路上

    按照示例 here 使用 CFT 创建 SageMaker 笔记本

    【讨论】:

      【解决方案2】:

      考虑使用AWS::SageMaker::NotebookInstanceLifecycleConfighttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sagemaker-notebookinstancelifecycleconfig.html

      1. 首先,您需要按名称引用AWS::SageMaker::NotebookInstance 资源中的LifecycleConfigName。这就是我使用!GetAtt 函数而不是!Ref 的原因。
      2. 然后,您需要创建您在上一步中引用的资源AWS::SageMaker::NotebookInstanceLifecycleConfig
      3. 最后,在Fn::Base64: 行中插入代码/文件下载命令。我在这个例子中使用了wget,但你可能可以使用其他 bash 命令,或者甚至下载更复杂的脚本并运行它。考虑脚本应该在不超过 5 分钟内运行:https://docs.aws.amazon.com/sagemaker/latest/dg/notebook-lifecycle-config.html

      请看下一个代码示例:

            JupyterNotebookInstance:
              Type: AWS::SageMaker::NotebookInstance
              Properties:
                InstanceType: ml.t3.medium
                RoleArn: !GetAtt JupyterNotebookIAMRole.Arn
                NotebookInstanceName: !Ref NotebookInstanceName
                LifecycleConfigName: !GetAtt JupyterNotebookInstanceLifecycleConfig.NotebookInstanceLifecycleConfigName
            JupyterNotebookInstanceLifecycleConfig:
              Type: "AWS::SageMaker::NotebookInstanceLifecycleConfig"
              Properties:
                OnStart:
                  - Content:
                      Fn::Base64: "cd /home/ec2-user/SageMaker/ && wget <your_files_url_here>"
      

      【讨论】:

        猜你喜欢
        • 2020-04-14
        • 1970-01-01
        • 1970-01-01
        • 2018-10-15
        • 1970-01-01
        • 2021-08-21
        • 1970-01-01
        • 2019-05-11
        • 2016-12-02
        相关资源
        最近更新 更多