SageMaker Shim for Grand Challenge
This repo contains a library that adapts algorithms that implement the Grand Challenge inference API for running in SageMaker.
The application contains:
- A
clickcli client with options to launch a web server - A
fastapiweb server that implements the SageMaker endpoints - and
pydanticmodels that interface between S3, and run the original inference jobs.
The application is compiled on Python 3.12 using pyinstaller, and then distributed as a statically linked binary using staticx.
It is able to adapt any container, including ones based on scratch or alpine images.
Usage
The binary is designed to be added to an existing container image that implements the Grand Challenge API. On Grand Challenge this happens automatically by using crane to add the binary, directories and environment variables to each container image. The binary itself will:
- Download the input files from the provided locations on S3 to
/input, optionally decompressing the inputs. - Execute the original container program in a subprocess.
This is found by inspecting the following environment variables:
GRAND_CHALLENGE_COMPONENT_CMD_B64J: the originalcmdof the container, json encoded as a base64 string.GRAND_CHALLENGE_COMPONENT_ENTRYPOINT_B64J: the originalentrypointof the container, json encoded as a base64 string.
- Upload the contents of
/outputto the given output S3 bucket and prefix.
Logging
CloudWatch does not offer separation of stdout and stderr by default.
sagemaker-shim includes a logging filter and formatter that creates structured logs from the application and subprocess.
This allows grand challenge to separate out internal, external, stdout and stderr streams.
These structured logs are JSON objects with the format:
{
"log": "", // The original log message
"level": "CRITICAL" | "ERROR" | "WARNING" | "INFO" | "DEBUG" | "NOTSET", // The severity level of the log
"source": "stdout" | "stderr", // The source stream
"internal": true | false, // Whether the source of the log is from sagemaker shim or the subprocess
"task": "" | null, // The ID of the task
}
sagemaker-shim serve
This starts the webserver on http://0.0.0.0:8080 which implements the SageMaker API. There are three endpoints:
-
/ping(GET): returns an empty 200 response if the container is healthy -
/execution-parameters(GET): returns the preferred execution parameters for AWS SageMaker Batch Inference -
/invocations(POST): SageMaker can make POST requests to this endpoint. The body contains the json encoded data required to run a single inference task:{ "pk": "unique-test-id", "inputs": [ { "relative_path": "interface/path", "bucket_name": "name-of-input-bucket", "bucket_key": "/path/to/input/file/in/bucket", "decompress": false, }, ... ], "output_bucket_name": "name-of-output-bucket", "output_prefix": "/prefix/of/output/files", "timeout": "PT1H10M30S" }
The endpoint will return an object containing the return code of the subprocess in
response["return_code"], and any outputs will be placed in the output bucket at the output prefix. A file with the inference outputs will also be located ats3://<output_bucket_name>/<output_prefix>/.sagemaker_shim/inference_result.json
sagemaker-shim invoke
This will invoke the model directly given the arguments. You can specify either:
-f / --file: S3 URI of a JSON file containing a list of task definitions, e.g.s3://my-bucket/invocations.json-t / --tasks: A JSON string of task definitions
In both cases the contents of the file or string will be an array of task objects:
[
{
"pk": "unique-test-id-1",
"inputs": [
...
],
"output_bucket_name": "name-of-output-bucket",
"output_prefix": "/prefix/of/output/files-1",
"timeout": "PT1H10M30S",
},
{
"pk": "unique-test-id-2",
"inputs": [
...
],
"output_bucket_name": "name-of-output-bucket",
"output_prefix": "/prefix/of/output/files-2",
"timeout": "PT2H10M30S",
}
]
A file with the inference outputs will be located at s3://<output_bucket_name>/<output_prefix>/.sagemaker_shim/inference_result.json.
Patching an Existing Container
To patch an existing container image in a registry see the example in tests/utils.py.
First you will need to get the original cmd and entrypoint using get_new_env_vars and get_image_config.
Then you can add the binary, set the new cmd, entrypoint, and environment variables with mutate_image.
Metadata
Release files for sagemaker-shim 0.8.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sagemaker_shim-0.8.3.tar.gz | 41.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sagemaker_shim-0.8.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 67.1 kB
Release files / sagemaker_shim-0.8.3.tar.gz
| Download URL | sagemaker_shim-0.8.3.tar.gz |
|---|---|
| Size | 41.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6975b3c6272dcd9702f8c3c17a599225c293c94aad433a18fa935bc86aced82f
|
|
BLAKE2b-256 checksum How to use checksums |
7da39af6708a797c220510dd14497eabc91919af5e582485f5d9369bb1270b52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency logRelease files / sagemaker_shim-0.8.3-py3-none-any.whl
| Download URL | sagemaker_shim-0.8.3-py3-none-any.whl |
|---|---|
| Size | 25.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16ba40dde975632b7d8588711147074d849cf2b9b285dfaedc37ce1a82bb91ba
|
|
BLAKE2b-256 checksum How to use checksums |
8f2b16490c36b3cf71418bf8c724fbdd5caeee5a95994f1c1a77968c464ac351
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 27, 2026.
Transparency log