{"slug": "build-receipt-extraction-api-using-amazon-sagemaker-amazon-ecs-vllm-and-google-4", "title": "Build Receipt Extraction API using Amazon SageMaker, Amazon ECS, vLLM and Google Gemma 4", "summary": "A developer built an AI receipt extraction API that uses the open-weight Google Gemma 4 model served through vLLM 0.19.1 on Amazon SageMaker endpoints and Amazon ECS to generate structured output—store name, price and purchase date—from receipts with varying templates and date formats. The build required a SageMaker Endpoint quota increase for g6.2xlarge instances, which AWS accounts default to a quota of 0 for all g-series GPU instances, and the developer chose g6.2xlarge at $1.222 per hour in the Oregon (us-west-2) region over g6.xlarge ($1.1267), g5.xlarge ($1.408), g5.2xlarge ($1.515) and g7.2xlarge ($3.15).", "body_md": "When extracting store name, price and purchase date from receipts, I face various challenges such as different receipt structures or templates and formats.\n\nTerms used for price may appear as total or grand total while purchase date formats can also be different — day/month/year or month/day/year. Then when extracting through manual entry such as typo during input the data and missed required data.\n\nTo fix all the challenges, I built a AI receipt extraction API using **Google Gemma 4** — open-source (open-weight) AI model and [**vLLM**](https://gallery.ecr.aws/deep-learning-containers/vllm) — open-source AI inference & serving to generate structured output from every receipt.\n\n**SERVICE QUOTAS**\n\nAWS accounts get default quotas for every service. For example, in Amazon SageMaker, default quota for all g-series GPU instances (g5, g6, g7) is 0. This means you must submit a quota increase request.\n\nIf not requested, provisioning of a new instance is blocked and you receive an error message during endpoint creation process. However, a quota request may be approved, denied or partially approved.\n\nOpen **Service Quotas** to submit a request for a **SageMaker Endpoint** quota increase. Enter **SageMaker** then click **View quotas**.\n\nEnter **g6.2xlarge for endpoint,** click bullet then click **Request increase at account level**.\n\nWhy **g6.2xlarge**? It is cheaper than similar instances (g5.2xlarge and g7.2xlarge) and only add $0.1 to get 2 times vCPU/GiB than g6.xlarge.\n\ng6.xlarge — 4 vCPU/16 GiB — $1.1267\n\ng6.2xlarge — 8 vCPU/32 GiB — $1.222\n\ng5.xlarge — 4 vCPU/16 GiB — $1.408\n\ng5.2xlarge — 8 vCPU/32 GiB — $1.515\n\ng7.2xlarge — 8 vCPU/32 GiB — $3.15\n\nThis price is based on the **Oregon (us-west-2)** region. If you want to use another region, you can view SageMaker pricing [on this website](https://aws.amazon.com/sagemaker/ai/pricing/) by select Real-time inference and select your region.\n\nEnter number in **Increase quota value**. The number must be greater than the current quota. Then click **Request**.\n\nWait a few seconds and the request for this instance is automatically approved. This means you can now use SageMaker endpoint.\n\n**SAGEMAKER STUDIO**\n\n[**SageMaker Studio**](https://aws.amazon.com/sagemaker/ai/studio/) is a SageMaker feature that serves as a web-based integrated development environment (IDE). Open **Amazon SageMaker** then select **Set up SageMaker Studio**.\n\nWait a few seconds until SageMaker Studio to become available then click **Open Studio** that automatically opens a new tab. The SageMaker Studio interface appears as shown in this screenshot below. Click JupyterLab logo in the top-left corner then click **Create JupyterLab space**.\n\nAfter the JupyterLab space has been created, click **Run space** then wait a few seconds until (click) **Open JupyterLab** button to become available that automatically opens a new tab.\n\nBack to **Amazon SageMaker** console (not SageMaker Studio), click **Domains** then select **QuickSetupDomain-**. In this domain, click **App configurations** then select **Enable Docker on this domain**. Wait a few seconds and now you can pull the vLLM image and push it to Amazon ECR.\n\n**vLLM IMAGE**\n\nBack to **JupyterLab**, click **Terminal** then clone this repository in the JupyterLab terminal and all files are now available.\n\n```\ngit clone https://github.com/budionosanai/google-gemma-sagemaker-vllm-fastapi-receipt-extraction.gitcd google-gemma-sagemaker-vllm-fastapi-receipt-extraction\n```\n\nRun this shell script in the **vllm** folder to pull and push the vLLM image to private ECR repository. This process takes a few minutes.\n\n```\ncd vllmchmod +x vllm-to-ecr.sh./vllm-to-ecr.sh\n```\n\nIn this shell script, I am using the vLLM version **0.19.1-gpu-py312-cu129-ubuntu22.04-sagemaker-v1.0 —** date pushed 7 months ago.\n\nIf you want to use the vLLM latest version, you can view vLLM [on this website](https://gallery.ecr.aws/deep-learning-containers/vllm) by select **Image tags** and sort them by **Date pushed** to finding the latest version then copy **Image URI** and replace **SOURCE_IMAGE** config with Image URI.\n\nOpen **Amazon ECR** then click **Repositories** under **Private registry**. vLLM image in the **vllm-gemma-4** repository is now available. This means you can deploy vLLM image to SageMaker endpoint.\n\n**SAGEMAKER ENDPOINT**\n\nRun this command to install [**Terraform**](https://registry.terraform.io/providers/-/aws/latest/docs) — infrastructure-as-code tool that means automatically provisioning of cloud resources through code of just a few lines.\n\n```\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"eval \"$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)\"brew install gccbrew tap hashicorp/tapbrew install hashicorp/tap/terraformterraform --version\n```\n\nView all Terraform files in the **terraform/sagemaker** folder.\n\nRun this Terraform command in the **terraform/sagemaker** folder to deploy **Google Gemma 4** model on vLLM image to SageMaker endpoint.\n\n```\ncd ..cd terraformcd sagemakerterraform initterraform planterraform apply --auto-approve\n```\n\nOpen **Amazon SageMaker** console (not SageMaker Studio), click **Deployments & inference** then select **Endpoints.** Wait a few minutes until SageMaker endpoint status becomes inservice. This means the SageMaker endpoint is ready to be used to serve requests.\n\n**RECEIPT EXTRACTION API IMAGE**\n\nView all files in the **app** folder. Execute this command to create a private ECR repository named **receipt-extraction-gemma-4**.\n\n```\ncd ..cd appaws ecr create-repository \\    --repository-name \"receipt-extraction-gemma-4\" \\    --image-scanning-configuration scanOnPush=false \\    --image-tag-mutability MUTABLE \\    --region \"us-west-2\" 2>/dev/null || echo \"Repository already exists, skipping creation.\"\n```\n\nHowever, when want to build and push receipt extraction API image to the private ECR repository, an error message appears as shown in this screenshot below.\n\nTo fix this error, execute this command in the **app** folder to install [SageMaker Docker Build](https://github.com/aws-samples/sagemaker-studio-image-build-cli) — a CLI tool for building Docker images in SageMaker Studio using AWS CodeBuild.\n\n```\npip install sagemaker-studio-image-build\n```\n\nBack to **Amazon SageMaker** console (not SageMaker Studio), click **Domains** then select **QuickSetupDomain-**. In this domain, click **User profiles** then select **default-** then click copy execution role for AWS IAM step as shown in this screenshot below.\n\nOpen **AWS IAM** to add permission policy for accessing AWS services. Click **Roles** under Access Management, then enter and select the name of execution role like this.\n\n```\nAmazonSageMaker-ExecutionRole-...\n```\n\nSageMaker Docker Build requires permissions policies to execute Docker image creation process using AWS CodeBuild and push the image to ECR such as:\n\nThen permissions policies to create container orchestration using Amazon ECS based on AWS Fargate such as:\n\nTo add the permissions policies above, click **Add permissions** then select **Attach policies**. Copy every permission policy above, check boxes then click **Add permissions** and display **Policy was successfully attached to role**.\n\nClick **Trust relationships** then select **Edit trust policy**. Replace JSON in Edit trust policy statement page with this JSON below then click **Update policy**.\n\n```\n{   \"Version\": \"2012-10-17\",   \"Statement\": [    {       \"Effect\": \"Allow\",       \"Principal\": {          \"Service\": \"sagemaker.amazonaws.com\"       },       \"Action\": \"sts:AssumeRole\"    },    {      \"Effect\": \"Allow\",      \"Principal\": {          \"Service\": \"codebuild.amazonaws.com\"      },      \"Action\": \"sts:AssumeRole\"     }   ]}\n```\n\nBack to **JupyterLab**, run this command in the **app** folder to build and push receipt extraction API image to the private ECR repository. This process takes a few minutes.\n\n```\nsm-docker build . --repository receipt-extraction-gemma-4:latest\n```\n\nOpen **Amazon ECR** then click **Repositories** under **Private registry**. Receipt extraction API image in the **receipt-extraction-gemma-4** repository is now available. This means you can deploy this API image to AWS Fargate on Amazon Elastic Container Service (ECS).\n\n[**Amazon ECS**](https://aws.amazon.com/ecs/) is a container orchestration service used to build and run container-based applications using virtual machines ([Amazon EC2](https://aws.amazon.com/ec2)) or serverless containers ([**AWS Fargate**](https://aws.amazon.com/fargate/)).\n\n**AMAZON ECS EXPRESS MODE**\n\n[**Amazon ECS Express Mode**](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/express-service-overview.html) offers faster deployment with minimal configuration. This mode requires only an ECR image URI, an [IAM execution role](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AmazonECSTaskExecutionRolePolicy.html) and an [IAM infrastructure role](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AmazonECSInfrastructureRoleforExpressGatewayServices.html) while manages all infrastructure using AWS Fargate-based service.\n\nI added an IAM task role to invoke the SageMaker endpoint. If this role is not attached, the task will fail.\n\nI use a custom VPC to have control over the networking side. If this custom VPC is not used, ECS Express Mode will automatically use the default VPC.\n\nView all Terraform files in the **terraform/ecs** folder. Run this Terraform command in the **terraform/ecs** folder to deploy receipt extraction API image to ECS Express Mode service.\n\n```\ncd ..cd terraformcd ecsterraform initterraform planterraform apply --auto-approve\n```\n\nOpen **Amazon ECS** then click **Clusters**. Wait a few minutes until ECS Express Mode service become available as shown in this screenshot below. You can see the number of container instances is 0 EC2 that means this service using AWS Fargate (not through EC2) then click cluster name.\n\nThe **receipt-extraction-gemma-4** service resources appears as shown in this screenshot below. The application URL is now available. Click target group and load balancer to view details.\n\nA target group is considered healthy as long as it has at least one healthy target. A healthy target group means that the group can receiving traffic directed by a load balancer.\n\nA load balancer receives requests from clients and forwards requests to a target group that is healthy.\n\nThis ECS Express Mode service are use receipt extraction API contaner image. Open **VPC console** then click **Your VPC** to make sure that your custom VPC is available.\n\nOpen https://re-...on.aws/health in your browser to make sure the API is healthy and return 200 OK.\n\nOpen https://re-...on.aws/docs in your browser to test the /predict API. Upload some sample photos from the **photos** folder then wait a few seconds to get the structured output.\n\nRun this Terraform command in the **terraform/ecs** folder to delete the ECS Express Mode service resources.\n\n```\nterraform destroy --auto-approve\n```\n\n**terraform destroy —** delete cloud (AWS) resources based your Terraform files. If you do not include **-auto-approve**, you must enter **yes** every want to apply your Terraform files.\n\n**AMAZON ECS STANDARD MODE**\n\n**Amazon ECS Standard Mode** offers full control over deployment including VPC networking, load balancer, auto-scaling and more. In this mode, task definition and service must be created manually.\n\nA task definition requires an IAM execution role, an IAM task role and an ECR image URI while a service requires that task definition, a launch type (**FARGATE** or EC2), a load balancer and a VPC networking.\n\nView all Terraform files in the **terraform/ecs-custom** folder. Run this Terraform command in the **terraform/ecs-custom** folder to deploy receipt extraction API image to ECS standard mode service.\n\n```\ncd ..cd terraformcd ecs-customterraform initterraform planterraform apply --auto-approve\n```\n\nOpen **Amazon ECS** then click **Clusters**. Wait a few minutes until ECS standard mode service become available.\n\nYou can see the number of container instances is 0 EC2 that means this service using AWS Fargate (not through EC2). Click cluster name then click service name as shown in this screenshot below.\n\nIn the health section, you can view load balancer target health include target group and load balancer. Click target group and load balancer to view details.\n\nOpen http://fastapi-alb-...elb.amazonaws.com/health in your browser to make sure the API is healthy and return 200 OK.\n\nOpen http://fastapi-alb-...elb.amazonaws.com/docs in your browser to test the /predict API. Upload some sample photos from the **photos** folder then wait a few seconds to get the structured output.\n\nRun this Terraform command in the **terraform/ecs-custom** folder to delete ECS Standard Mode service resources.\n\n```\nterraform destroy --auto-approve\n```\n\nRun this Terraform command in the **terraform/sagemaker** folder to delete SageMaker endpoint resources.\n\n```\nterraform destroy --auto-approve\n```\n\nRun this command to delete the vLLM image and the receipt extraction API image from the private ECR repository.\n\n```\naws ecr delete-repository --repository-name receipt-extraction-gemma-4 --force --region us-west-2aws ecr delete-repository --repository-name vllm-gemma-4 --force --region us-west-2\n```\n\nIn SageMaker Studio JupyterLab, click Stop space and [delete your SageMaker Studio domain.](https://docs.aws.amazon.com/sagemaker/latest/dg/gs-studio-delete-domain.html#gs-studio-delete-domain-studio)\n\nResources:\n\n1. [Amazon SageMaker documentation](https://docs.aws.amazon.com/sagemaker/)\n\n2. [Google Gemma 4 on vLLM documentation](https://docs.vllm.ai/projects/recipes/en/latest/Google/Gemma4.html)\n\n3. [Google Gemma 4 model documentation](https://ai.google.dev/gemma/docs/core/model_card_4)\n\n4. [Terraform for SageMaker endpoint documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sagemaker_endpoint)\n\n5. [Amazon ECS documentation](https://docs.aws.amazon.com/ecs/)\n\n6. [Terraform for ECS Express mode documentation](https://registry.terraform.io/providers/-/aws/latest/docs/resources/ecs_express_gateway_service)\n\nThank you,\n\nBudi.\n\n[Build Receipt Extraction API using Amazon SageMaker, Amazon ECS, vLLM and Google Gemma 4](https://pub.towardsai.net/build-receipt-extraction-api-using-amazon-sagemaker-amazon-ecs-vllm-and-google-gemma-4-44dc14f4d2d2) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/build-receipt-extraction-api-using-amazon-sagemaker-amazon-ecs-vllm-and-google-4", "canonical_source": "https://pub.towardsai.net/build-receipt-extraction-api-using-amazon-sagemaker-amazon-ecs-vllm-and-google-gemma-4-44dc14f4d2d2?source=rss----98111c9905da---4", "published_at": "2026-12-05 10:46:19+00:00", "updated_at": "2026-12-05 11:12:59.921828+00:00", "lang": "en", "topics": ["large-language-models", "ai-infrastructure", "ai-tools", "mlops", "ai-products"], "entities": ["Google Gemma 4", "vLLM", "Amazon SageMaker", "Amazon ECS", "Amazon Web Services", "Amazon Elastic Container Registry", "JupyterLab"], "also_reported_by": [], "takeaway": "Serve Google Gemma 4 with vLLM 0.19.1 on a SageMaker g6.2xlarge endpoint ($1.222/hr in us-west-2) to extract store name, price and purchase date as structured output from receipts with inconsistent templates and date formats.", "recommendation": {"advice": "Request a SageMaker Endpoint quota increase for g6.2xlarge before deploying, since the default g-series GPU quota is 0; at $1.222/hr it costs $0.1 more than g6.xlarge for double the vCPU and memory.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/build-receipt-extraction-api-using-amazon-sagemaker-amazon-ecs-vllm-and-google-4", "markdown": "https://wpnews.pro/news/build-receipt-extraction-api-using-amazon-sagemaker-amazon-ecs-vllm-and-google-4.md", "text": "https://wpnews.pro/news/build-receipt-extraction-api-using-amazon-sagemaker-amazon-ecs-vllm-and-google-4.txt", "jsonld": "https://wpnews.pro/news/build-receipt-extraction-api-using-amazon-sagemaker-amazon-ecs-vllm-and-google-4.jsonld"}}