简体   繁体   中英

Passing Parameters to Sagemaker Notebook Instance

I want to pass the name of a file from a labda function to sagemaker notebook instance

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?

You can create tags using the boto3 client add_tags(..) method to pass values to your notebook instance from your lambda.

Then in your startup script you can read from that tag and set an environment variable containing the value in the tag. You can modify the script from the following AWS sagemaker on-start script example to set your environment variable.

You can now use that environment variable inside your notebook or python file which contains the value you need (in your case the name of the file).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM