{"id":22428502,"url":"https://github.com/kwame-mintah/aws-lambda-model-deployment","last_synced_at":"2026-04-28T20:33:55.659Z","repository":{"id":224416926,"uuid":"763011367","full_name":"kwame-mintah/aws-lambda-model-deployment","owner":"kwame-mintah","description":"A lambda to deploy a machine learning model inference via serverless. Will create a new model, endpoint configuration and serverless endpoint configuration within AWS SageMaker.","archived":false,"fork":false,"pushed_at":"2024-08-06T20:46:41.000Z","size":120,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T11:43:47.790Z","etag":null,"topics":["aws","aws-lambda","model-deployment","python","python311"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kwame-mintah.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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":"2024-02-25T10:19:43.000Z","updated_at":"2024-08-06T20:46:45.000Z","dependencies_parsed_at":"2024-02-26T21:43:20.831Z","dependency_job_id":"2d77700c-4975-400a-bdd3-080c82a06c19","html_url":"https://github.com/kwame-mintah/aws-lambda-model-deployment","commit_stats":null,"previous_names":["kwame-mintah/aws-lambda-model-deployment"],"tags_count":14,"template":false,"template_full_name":"kwame-mintah/aws-lambda-function-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwame-mintah%2Faws-lambda-model-deployment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwame-mintah%2Faws-lambda-model-deployment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwame-mintah%2Faws-lambda-model-deployment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kwame-mintah%2Faws-lambda-model-deployment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kwame-mintah","download_url":"https://codeload.github.com/kwame-mintah/aws-lambda-model-deployment/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245798538,"owners_count":20673901,"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","aws-lambda","model-deployment","python","python311"],"created_at":"2024-12-05T20:15:02.312Z","updated_at":"2026-04-28T20:33:50.615Z","avatar_url":"https://github.com/kwame-mintah.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS Lambda Model Deployment\n\n[![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3121/)\n[![🚧 Bump version](https://github.com/kwame-mintah/aws-lambda-model-deployment/actions/workflows/bump-repository-version.yml/badge.svg)](https://github.com/kwame-mintah/aws-lambda-model-deployment/actions/workflows/bump-repository-version.yml)\n[![🚀 Push Docker image to AWS ECR](https://github.com/kwame-mintah/aws-lambda-model-deployment/actions/workflows/push-docker-image-to-aws-ecr.yml/badge.svg)](https://github.com/kwame-mintah/aws-lambda-model-deployment/actions/workflows/push-docker-image-to-aws-ecr.yml)\n[![🧹 Run linter](https://github.com/kwame-mintah/aws-lambda-model-deployment/actions/workflows/run-python-linter.yml/badge.svg)](https://github.com/kwame-mintah/aws-lambda-model-deployment/actions/workflows/run-python-linter.yml)\n\u003ca href=\"https://github.com/psf/black\"\u003e\u003cimg alt=\"Code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"\u003e\u003c/a\u003e\n\nA lambda to deploy a model via serverless after training has completed. The model artifacts will be used to create a new model,\nendpoint configuration and serverless endpoint configuration within SageMaker.\n\nThis repository does not create other necessarily resources within AWS, this is created via Terraform found here [terraform-aws-machine-learning-pipeline](https://github.com/kwame-mintah/terraform-aws-machine-learning-pipeline).\nFor more details on the entire flow and how this lambda is deployed, see [aws-automlops-serverless-deployment](https://github.com/kwame-mintah/aws-automlops-serverless-deployment).\n\n# Flowchart\n\nThe [diagram below](https://mermaid.js.org/syntax/flowchart.html#flowcharts-basic-syntax) demonstrates what happens when the lambda is trigger, when a new `.tar.gz` object has been uploaded to the S3 Bucket.\n\n```mermaid\ngraph LR\n  S0(Start)\n  T1(Create SageMaker model with output artifact)\n  T2(Create Endpoint configuration using xgboost)\n  T3(Create Serverless endpoint)\n  T4(Send message to Model Evaluation SQS)\n  E0(End)\n\n  S0--\u003eT1\n  T1--\u003eT2\n  T2--\u003eT3\n  T3--\u003eT4\n  T4--\u003eE0\n```\n\n# Notice\n\nPlease note because the SageMaker endpoint deployed is serverless, means [`DataCaptureConfig`](https://docs.aws.amazon.com/sagemaker/latest/dg/model-monitor-data-capture-endpoint.html),\nis not supported and will have to rely on CloudWatch logs as per official [documentation](https://docs.aws.amazon.com/sagemaker/latest/dg/serverless-endpoints-monitoring.html).\n\nBecause endpoint(s) and endpoint configuration(s) are not created via Terraform, these will not be deleted when\ndestroying the environment and will need to be deleted manually or programmatically, for example if the new model is\nnot perform as expected, delete all related configurations created for inference.\n\nIf Terraform has destroyed all related infrastructure related to SageMaker, for example S3 bucket containing model output\nhas been deleted, then you are unable to invoke the endpoint because the model no longer exists.\n\n## Development\n\n### Dependencies\n\n- [Python](https://www.python.org/downloads/release/python-3121/)\n- [Docker for Desktop](https://www.docker.com/products/docker-desktop/)\n- [Amazon Web Services](https://aws.amazon.com/?nc2=h_lg)\n\n## Usage\n\n1. Build the docker image locally:\n\n   ```shell\n   docker build --no-cache -t model_deployment:local .\n   ```\n\n2. Run the docker image built:\n\n   ```shell\n   docker run --platform linux/amd64 -p 9000:8080 model_deployment:local\n   ```\n\n3. Send an event to the lambda via curl:\n   ```shell\n   curl \"http://localhost:9000/2015-03-31/functions/function/invocations\" -d '{\u003cEXPAND_BELOW_AND_REPLACE_WITH_JSON_BELOW\u003e}'\n   ```\n   \u003cdetails\u003e\n   \u003csummary\u003eExample AWS S3 event received\u003c/summary\u003e\n   ```json\n   {\n     \"Records\": [\n       {\n         \"eventVersion\": \"2.0\",\n         \"eventSource\": \"aws:s3\",\n         \"awsRegion\": \"us-east-1\",\n         \"eventTime\": \"1970-01-01T00:00:00.000Z\",\n         \"eventName\": \"ObjectCreated:Put\",\n         \"userIdentity\": { \"principalId\": \"EXAMPLE\" },\n         \"requestParameters\": { \"sourceIPAddress\": \"127.0.0.1\" },\n         \"responseElements\": {\n           \"x-amz-request-id\": \"EXAMPLE123456789\",\n           \"x-amz-id-2\": \"EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH\"\n         },\n         \"s3\": {\n           \"s3SchemaVersion\": \"1.0\",\n           \"configurationId\": \"testConfigRule\",\n           \"bucket\": {\n             \"name\": \"example-bucket\",\n             \"ownerIdentity\": { \"principalId\": \"EXAMPLE\" },\n             \"arn\": \"arn:aws:s3:::example-bucket\"\n           },\n           \"object\": {\n             \"key\": \"2024-02-23/output/xgboost-2024-02-23-18-04-06-024/output/model.tar.gz\",\n             \"size\": 1024,\n             \"eTag\": \"0123456789abcdef0123456789abcdef\",\n             \"sequencer\": \"0A1B2C3D4E5F678901\"\n           }\n         }\n       }\n     ]\n   }\n   ```\n   \u003c/details\u003e\n\n## GitHub Action (CI/CD)\n\nThe GitHub Action \"🚀 Push Docker image to AWS ECR\" will checkout the repository and push a docker image to the chosen AWS ECR using\n[configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials/tree/v4.0.1/) action. The following repository secrets need to be set:\n\n| Secret             | Description                  |\n|--------------------|------------------------------|\n| AWS_REGION         | The AWS Region.              |\n| AWS_ACCOUNT_ID     | The AWS account ID.          |\n| AWS_ECR_REPOSITORY | The AWS ECR repository name. |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwame-mintah%2Faws-lambda-model-deployment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkwame-mintah%2Faws-lambda-model-deployment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwame-mintah%2Faws-lambda-model-deployment/lists"}