Deploy calculatecost2 to dev

Pushing to dev triggers the GitHub Actions deploy workflow, which builds the container image and runs sam deploy. It takes roughly 15–20 minutes.

cd ~/stacks/villaCalculateCost2
git add -A && git commit -m "..." && git push origin dev
gh run list --workflow deploy --branch dev --limit 2
gh run watch <run-id> --exit-status

Confirm the Lambda actually rolled over — a green workflow with an old timestamp means the deploy didn’t reach the function:

AWS_PROFILE=default aws lambda get-function-configuration \
  --function-name calculate-cost-3-dev --region ap-southeast-1 \
  --query '{LastModified:LastModified,State:State}'

The Build workflow fails on every commit

SonarCloud rejects the SONAR_TOKEN (Failed to query JRE metadata). It has failed on every push for weeks and is unrelated to your change. Only the deploy workflow matters. Worth fixing separately so the signal isn’t permanently red.

Tests before pushing

python3 -m pytest test/coupon/ test/order/ test/shipping/ -q

Some tests hit AWS and the price service, so run them with credentials available. pyarrow is an easy one to be missing locally — four order tests fail on import without it, which is an environment problem rather than a regression.

Verify against dev after deploy

Get an API key and re-run the coupon matrix — see run-coupon-test-matrix.

APIKEY=$(python3 -c 'import json,boto3; r=boto3.Session(profile_name="default").client("lambda","ap-southeast-1").invoke(FunctionName="get-apikey-master",Payload=b"{}"); print(json.loads(json.loads(r["Payload"].read())["body"])["key"])')
 
curl -sS -X POST 'https://dev.villamarket.net/api/calculatePrice/calculateCost2' \
  -H "Authorization: Bearer $APIKEY" -H 'Content-Type: application/json' \
  -d '{"ownerId":"t","branchId":"1000","couponCodeList":["FREESHIP"],"bypassCache":true,
       "orderSource":"WEB","productList":[{"cprcode":220772,"quantity":3}],
       "shipping":{"shippingType":"DELIVERY","scheduleList":[{"mode":"REGULAR"}],
                   "shippingPostcode":"10110","shippingLat":13.748,"shippingLon":100.557}}'

Always send bypassCache: true when testing or you will be reading yesterday’s shipping cost.

Rollback

Revert the commit and push again — the pipeline is the only supported path to the function.

Do not promote to master casually

calculate-cost-3-master still targets the legacy coupon checker. Pushing this branch’s coupon wiring to master repoints production at the villa-ecommerce dev checker. That needs its own plan: a prod checker, migrated coupon data, and resource policies for the master role. See the migration doc in the repo.