AWS Builder Center

What sam build doesn't tell you: five bugs that only appeared after deploying

Our household allergen scanner passed 125 tests and ran clean locally, then broke five different ways on its first real deploy — a native wheel built for the wrong CPU, a signing key set on one function out of five, and a DynamoDB key that quietly changed our de-duplication rules. Here is each one, why local testing could not catch it, and the fix.

We built AaharKavach ("food shield") for the First Commit hackathon: you scan a packaged-food barcode, or photograph the ingredients panel, and get a plain-English verdict per person in your household — not one merged pass/fail. A parent scanning for "dairy" will not find "sodium caseinate". E322 means nothing on a label, and a latex allergy means banana can trigger a reaction. The app resolves all of that and answers for each person separately, scaled to how severe their restriction is.
The backend is five Lambda functions behind API Gateway with three DynamoDB tables, defined in a SAM template. Amazon Textract reads the ingredients panel from label photos. Authorization is  Cedar , AWS's open-source policy engine. The frontend is Next.js on Amplify Hosting.
Locally, everything worked. 125 tests green, a clean  npm run build , a clean  sam build . Then we deployed, and found five bugs in an afternoon — every one of them invisible on a laptop. They are all fairly ordinary mistakes, which is exactly why they are worth writing down.

1.  sam build  only resolves pip dependencies

Our handlers import a knowledge-base package ( data/ ) and an agent package ( agent/ ) that live at the repo root — outside  CodeUri . Locally those imports resolve because the repo root is on  sys.path .  sam build  packages  CodeUri  and its  requirements.txt , and nothing else. It reports success. The deploy succeeds. Then every request 500s on  ImportError .
The fix is a custom builder. Set  BuildMethod: makefile  in the function's  Metadata , and put a  Makefile  inside  CodeUri  with a  build-<LogicalId>  target that assembles the real package:
build-ProfilesFunction:
cp -r "$(ROOT)/backend/src/." "$(ARTIFACTS_DIR)/"
cp -r "$(ROOT)/data" "$(ARTIFACTS_DIR)/data"
cp -r "$(ROOT)/agent" "$(ARTIFACTS_DIR)/agent"
$(PY) -m pip install -q -r "$(ROOT)/backend/src/requirements.txt" -t "$(ARTIFACTS_DIR)"
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article