Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup env variable in aws SageMaker container (bring your own container)

We are using aws sagemaker that is using ecs container, Is there a way, we can setup environment variable (e.g. stage or prod) in container when calling sagemaker api using low level python sdk

like image 987
rajnish Avatar asked Jul 06 '18 17:07

rajnish


People also ask

How do I use an environment variable in AWS?

To set environment variablesSign in to the AWS Management Console and open the Amplify console . In the Amplify console, choose App Settings, and then choose Environment variables. In the Environment variables section, choose Manage variables. In the Manage variables section, under Variable, enter your key.


1 Answers

Even invoking the API directly (which is lower level than using the python SDK) you cannot directly set environment arbitrary variables inside the container. You can however pass arbitrary hyperparameters in as configuration for a TrainingJob, for example pass in a hyperparameter like {"mystage": "prod"}. Hyperparameters show up in the container in a file called /opt/ml/input/config/hyperparameters.json which is a simple key-value map as a JSON object. You can use this to set the environment variable in a launching script like this:

#!/bin/bash

export STAGE=$(jq -r ".mystage" /opt/ml/input/config/hyperparameters.json)

# Now run your code...

You can get SageMaker to invoke this script either by making it the ENTRYPOINT in your Dockerfile, or by calling it train and making sure it's on the PATH for the shell if you're not setting an ENTRYPOINT.

like image 111
Leopd Avatar answered Sep 19 '22 10:09

Leopd