Shipping rate calculator

chevron-rightArchitecturehashtag

[Seller UI] → [API Gateway] → [AWS Lambda] → [Courier APIs] ↓ [RDS / DynamoDB / S3]

Frontend: Nextjs form

chevron-rightWorkinghashtag

Sends a POST request to your API Gateway endpoint with:

Hosted on cloudflare pages

Backend with Lambda

chevron-rightWorkinghashtag

Your AWS Lambda function will:

  1. Receive the payload from API Gateway

  2. Call 4–5 courier partner APIs concurrently (using asyncio or ThreadPoolExecutor)

  3. Return a unified JSON response with rates and delivery times

Example (Python/FastAPI-like Lambda handler):

Fast cold start (Python 3.10/3.11 runtime) ✅ Concurrent API calls → low latency ✅ Serverless → no infra management

chevron-rightAPI Gatewayhashtag

API Gateway

  • Create a REST API in AWS API Gateway.

  • Connect /rates endpoint to the Lambda.

  • Enable CORS so your frontend can call it directly.

  • Add rate limiting or usage plans (100/day is trivial).


Step 2: Create API Gateway

  1. Go to API Gateway → Create API

    • Choose “REST API”

    • Select “Build”

    • Name: shipping-rate-api

    • Endpoint Type: Regional

  2. Create a Resource

    • Click Actions → Create Resource

    • Name: rates

    • Resource Path: /rates

  3. Create a Method

    • Under /rates, click Create Method → POST

    • Integration type: Lambda Function

    • Choose your Lambda: shipping-rate-calc

    • Save → Allow permission

  4. Enable CORS

    • Select /rates → Actions → Enable CORS

    • Set:

      • Allowed Origins: * (or restrict to your frontend domain)

      • Allowed Methods: POST

      • Allowed Headers: Content-Type, Authorization

  5. Deploy the API

    • Actions → Deploy API

    • Create a new Stage: prod

You’ll get an endpoint like:

chevron-rightCollect logs/datahashtag

Security

  • Store courier API keys in AWS Systems Manager Parameter Store or Secrets Manager

  • Lambda retrieves them securely at runtime:

chevron-rightTestinghashtag

test with FASTAPI Swagger UI

Last updated