r/aws•
mr_data_

Can we run a python script in AWS Sagemaker using boto3 from a local machine?

technical question

Hi Folks

Here's what I am trying to do:

In my application that resides outside aws, I take some user inputs, and trigger scripts that are inside a Sagemaker notebook instance.

I am able to start or create a new instance using boto3, and also use lifecycle configuration to run some starter script while the instance turns on. But I want to run multiple scripts in short intervals based on user inputs, so I don't want to restart my instance each time with a new lifecycle configuration script. I am trying to find if there is a way to execute shell commands in sagemaker using boto3 (or any other way).

You may wonder why I am doing this. We are building a light weight auto ml type solution where the training scripts utilize sagemaker specific functionalities, so I thought it's simpler to keep them inside sagemaker. But I am facing a tough time dealing with talking to these scripts from outside aws eco-system.

Posted Mar 9, 2022, 10:43 AM UTC

17
lastmonty•

Notebooks can be parameterized and run, check out papermill or ploomber.

The solution I can think of is make a docker image of your stuff and trigger a sagemaker processing job passing the parameters to the script via environment variables.

1
bojanderson•

I am able to start or create a new instance using boto3

Are you talking about Sagemaker training jobs and/or processing jobs in this sentence?

1
mr_data_OP•

No, just a notebook instance. The machine where the scripts are present.

1
bojanderson•

So at the end of the post you mention "Sagemaker functionality". What is this Sagemaker functionality you're referring to that you want to use?

1
mr_data_OP•

I meant using the algos that come with Sagemaker estimators, their hyper-paramter tuning capability, and reusing the model later for prediction pipelines.

I didn't try the Sagemaker processing jobs. That seems to be the right way to do this, but might mean I convert my notebook to a script.

My goal is to give some light weight auto ML type platform, and I want to give users a capability to either build their models purely from a UI, or in case they want, give them an environment where they can play around.

For the first part where I give only a UI, a python script and prediction pipelines work. But that's not ideal if user wants to tweak the script and try out other stuff - where notebooks would be very helpful.

1
bojanderson•

So you imagine the user running snippets of code in a notebook? And writing code or adjusting it? Or do imagine then having a GUI and picking some settings and code running in the background?

1