Skip to content

Deployment Guide

Prerequisites

  • AWS CLI configured with the villa-ecommerce profile
  • Docker installed and running
  • SAM CLI installed
  • Access to both AWS accounts:
    • 017176210331 -- primary account (Lambda, API Gateway, S3)
    • 394922924679 -- data account (DynamoDB, coupon/voucher Lambdas)

Build

cd villaCalculateCost4
sam build --profile villa-ecommerce

Deploy

sam deploy \
  --profile villa-ecommerce \
  --stack-name villaCalculateCost4 \
  --resolve-s3 \
  --resolve-image-repos \
  --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM \
  --region ap-southeast-1 \
  --no-confirm-changeset

Verify

After deployment, confirm the endpoint responds:

curl -X POST https://api.villaecommerce.com/calculatecost4 \
  -H "Content-Type: application/json" \
  -d '{"productList":[],"branchId":"1000"}'

A successful response returns HTTP 200 with a JSON body containing grandTotal, subTotal, and other calculated fields.


Test UI Update

To push a new version of the Test UI:

aws s3 cp test-ui/index.html \
  s3://villa-calculatecost4-test-ui-017176210331/index.html \
  --content-type "text/html" \
  --profile villa-ecommerce

The CloudFront distribution (E3O98IU4WJ5P9X) picks up changes automatically. To force an immediate refresh:

aws cloudfront create-invalidation \
  --distribution-id E3O98IU4WJ5P9X \
  --paths "/index.html" \
  --profile villa-ecommerce

Environment Variables

Variable Description Example
CROSS_ACCOUNT_ROLE_ARN IAM role for cross-account access arn:aws:iam::394922924679:role/villaCalculateCost4-CrossAccountAccess
PRICE_TABLE_NAME DynamoDB price table price-database-2-dev-manual
PRODUCT_TABLE_NAME DynamoDB product table product-table-dev-manual
COUPON_FUNCTION_ARN Coupon Lambda ARN arn:aws:lambda:ap-southeast-1:394922924679:function:coupon3-checker-dev
VOUCHER_FUNCTION_ARN Voucher Lambda ARN (see SAM template)
NATIONWIDE_FUNCTION_ARN Nationwide shipping Lambda ARN (see SAM template)
REGION AWS region ap-southeast-1
BRANCH Branch name dev-manual

These are configured in the SAM template (template.yaml) under the Lambda function's Environment.Variables section and injected at deploy time.


Rollback

If a deployment causes issues, roll back to the previous CloudFormation stack version:

aws cloudformation rollback-stack \
  --stack-name villaCalculateCost4 \
  --profile villa-ecommerce \
  --region ap-southeast-1

To check rollback status:

aws cloudformation describe-stacks \
  --stack-name villaCalculateCost4 \
  --profile villa-ecommerce \
  --region ap-southeast-1 \
  --query 'Stacks[0].StackStatus'

Infrastructure

For the full architecture diagram and cross-account data flow, see the Architecture page.