| Key | Value |
|---|---|
| Services | SageMaker, S3 |
| Integrations | AWS SDK (boto3) |
| Categories | ML; Inference |
A demo application illustrating how to host PyTorch ML models with SageMaker using LocalStack. The sample creates a SageMaker endpoint for an MNIST digit recognition model and demonstrates invocations both directly on the container and via the boto3 SDK.
Before running this example, set up your Docker client to pull AWS Deep Learning images (more info):
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 763104351884.dkr.ecr.us-east-1.amazonaws.comBecause the images tend to be heavy (multiple GB), pull them beforehand:
docker pull 763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-inference:1.5.0-cpu-py3- A valid LocalStack for AWS license. Your license provides a
LOCALSTACK_AUTH_TOKENto activate LocalStack. - Docker
localstackCLI- Python 3.8+
make checkmake installexport LOCALSTACK_AUTH_TOKEN=<your-auth-token>
make startmake runThe script creates an S3 bucket, uploads model data, creates a SageMaker endpoint, and invokes it to predict digit classes. You should see output similar to:
Creating bucket...
Uploading model data to bucket...
Creating model in SageMaker...
Adding endpoint configuration...
Creating endpoint...
Checking endpoint status...
Endpoint not ready - waiting...
Checking endpoint status...
Endpoint ready!
Invoking via boto...
Predicted digits: [7, 3]
Invoking endpoint directly...
Predicted digits: [2, 6]
To try out the serverless run, remove the comment in main.py and run the example again.
This code is available under the Apache 2.0 license.