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
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With