簡體   English   中英

將參數傳遞給 Sagemaker Notebook 實例

[英]Passing Parameters to Sagemaker Notebook Instance

我想將文件名從 labda function 傳遞給 sagemaker notebook 實例

I am using Sagemaker notebook to perform a preprocessing job when a file landed in the s3 bucket. As such, I wrote a lambda function triggered by an S3 event that start the notebook. The lambda code is like 

` import boto3
 import logging

 def lambda_handler(event, context):
     print("notebook starting .....")
     client = boto3.client('sagemaker')
     client.start_notebook_instance(NotebookInstanceName='preprocess-dataset')
     print("notebook started .....")
     return 0
`

I want to pass the name of the file to this notebook so the notebook read the content of the file. How can I do that?

您可以使用 boto3 客戶端add_tags(..)方法創建標簽,以將值從您的 lambda 傳遞到您的筆記本實例。

然后在您的啟動腳本中,您可以從該標簽中讀取並設置一個包含標簽中值的環境變量。 您可以修改以下AWS sagemaker 啟動腳本示例中的腳本以設置您的環境變量。

您現在可以在筆記本或 python 文件中使用該環境變量,其中包含您需要的值(在您的情況下為文件名)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM