{"id":18573138,"url":"https://github.com/localstack-samples/sample-mnist-digit-recognition-sagemaker","last_synced_at":"2025-04-10T07:31:49.449Z","repository":{"id":155087621,"uuid":"632520066","full_name":"localstack-samples/sample-mnist-digit-recognition-sagemaker","owner":"localstack-samples","description":"Demo to run the MNIST handwritten digit model on a locally running SageMaker endpoint","archived":false,"fork":false,"pushed_at":"2024-08-06T04:57:13.000Z","size":1316,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-03-24T18:06:56.041Z","etag":null,"topics":["aws","developer-hub","lambda","localstack","localstack-developer-hub","machine-learning","s3","s3-website","sagemaker","servleress"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/localstack-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-25T15:18:55.000Z","updated_at":"2024-09-20T20:03:40.000Z","dependencies_parsed_at":"2024-08-06T07:11:12.407Z","dependency_job_id":"ab2af2e3-0032-4e7e-a197-de4959a17fbe","html_url":"https://github.com/localstack-samples/sample-mnist-digit-recognition-sagemaker","commit_stats":null,"previous_names":["localstack-samples/sample-mnist-digit-recognition-sagemaker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-mnist-digit-recognition-sagemaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-mnist-digit-recognition-sagemaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-mnist-digit-recognition-sagemaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-mnist-digit-recognition-sagemaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localstack-samples","download_url":"https://codeload.github.com/localstack-samples/sample-mnist-digit-recognition-sagemaker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248176384,"owners_count":21060058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","developer-hub","lambda","localstack","localstack-developer-hub","machine-learning","s3","s3-website","sagemaker","servleress"],"created_at":"2024-11-06T23:08:07.971Z","updated_at":"2025-04-10T07:31:49.065Z","avatar_url":"https://github.com/localstack-samples.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MNIST handwritten digit recognition model running on a local SageMaker endpoint\n\n| Key          | Value                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Environment  | \u003cimg src=\"https://img.shields.io/badge/LocalStack-deploys-4D29B4.svg?logo=data:image/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QwEfiIRheKKUAvjuuu7m2tpakPdMmcYYI1rre0EQ1LPo9w82qyNziMdZ3AAAAABJRU5ErkJggg==\"\u003e |\n| Services     | S3, SageMaker, Lambda                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |\n| Integrations | AWS SDK                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |\n| Categories   | Serverless, S3 website, Lambda function URLs, SageMaker, Machine Learning, JavaScript, Python                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |\n| Level        | Intermediate                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |\n\n## Introduction\n\nThis is a sample application that demonstrates how to use SageMaker on LocalStack.\nA simple web frontend allows users to draw a digit and submit it to a locally running SageMaker endpoint.\nThe endpoint returns a prediction of the digit, which is then displayed in the web frontend.\nRequest handling is performed by a Lambda function, accessible via a function URL, that uses the SageMaker SDK to invoke the endpoint.\n\nHere's a short summary of AWS service features we use:\n* S3 website\n* Lambda function URLs\n* SageMaker endpoint\n\nHere's the web application in action:\n\nhttps://user-images.githubusercontent.com/39307517/234888629-4bd9deb8-ecdd-46a6-91d6-908b9f2a443c.mov\n\n## Architecture overview\n\n![Architecture Diagram](/assets/architecture-diagram.png?raw=True \"Architecture Diagram\")\n\n\n## Prerequisites\n\n### Dev environment\n\nCreate a virtualenv and install all the development dependencies there:\n\n```bash\npython -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\n```\n\nIf you'd like to perform training locally, you'll need to install the ml dev dependencies as well:\n\n```bash\npip install -r ml/requirements.txt\n```\n\nYou'll also need npm/node installed to build the web application. Please install according to official guidelines: https://github.com/nvm-sh/nvm\n\n### Download pytorch container image\nAs our inference container, we use the PyTorch inference container from the AWS ECR.\n\n```bash\naws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 763104351884.dkr.ecr.eu-central-1.amazonaws.com\ndocker pull 763104351884.dkr.ecr.eu-central-1.amazonaws.com/pytorch-inference:1.10.2-cpu-py38-ubuntu20.04-sagemaker\n```\n\n### LocalStack\n\nStart LocalStack Pro with your Auth Token:\n\n```bash\nPERSISTENCE=1 LOCALSTACK_AUTH_TOKEN=... localstack start\n```\n\n## Instructions\n\nFirst, we install the dependencies for the Web application in the `web` directory:\n```\n(cd web; npm install)\n```\n\nYou can then create the AWS infrastructure on LocalStack by running the `deploy/deploy_app.py` script (make sure to have the virtual environment activated):\n```\nsource .venv/bin/activate\npython deploy/deploy_app.py\n```\n\nThis script will create the SageMaker endpoint with the model, which it first uploads to a bucket.\nThe script will also create a lambda function that will be used to invoke the endpoint.\nFinally, the script will build the web application and then create a s3 website to host it.\n\n### Using the application\n\nOnce deployed, visit http://mnist-website.s3-website.localhost.localstack.cloud:4566\n\nDraw something in the canvas and click on the button that says `Predict`.\n\nAfter a few moments the resulting prediction should be displayed in the box to the right.\n\n![Demo Picture](/assets/demo-pic.png?raw=True \"Demo Picture\")\n\n\n## Serverless SageMaker Endpoint\n\nTo switch to a serverless SageMaker endpoint you can also execute the deployment script with the additional `-s` or `--serverless` flag:\n\n```bash\npython deploy/deploy_app.py --serverless\n```\n\n## License\n\nThe code of this sample application is published under the Apache 2.0 license (see `LICENSE`).\n\n## Contributing\n\nWe appreciate your interest in contributing to our project and are always looking for new ways to improve the developer experience. We welcome feedback, bug reports, and even feature ideas from the community.\nPlease refer to the [contributing file](CONTRIBUTING.md) for more details on how to get started. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fsample-mnist-digit-recognition-sagemaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocalstack-samples%2Fsample-mnist-digit-recognition-sagemaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fsample-mnist-digit-recognition-sagemaker/lists"}