Skip to content

Phathdt/test-lambda

Repository files navigation

Hono + Lambda + SQS on Floci (Turborepo · pnpm)

End-to-end sample wiring up:

client → Lambda(producer, Hono) → SQS(hello-queue) → Lambda(consumer) → CloudWatch Logs

…all running locally inside Floci — the free, open-source AWS local emulator. Workspaces managed by pnpm and orchestrated by Turborepo.

Stack

  • pnpm workspaces + Turborepo task pipeline
  • Hono v4 with hono/aws-lambda adapter (producer)
  • @aws-sdk/client-sqs v3 (producer → SQS)
  • esbuild bundles each Lambda to a single CJS file
  • Floci runs Lambdas in real Docker containers (public.ecr.aws/lambda/nodejs:22) and auto-injects AWS_ENDPOINT_URL=http://floci:4566 so the producer can reach SQS on the shared floci-net Docker network
  • AWS CLI v2 drives setup/deploy/log-tail from the host

Layout

.
├── apps/
│   ├── producer/         # Hono Lambda — GET /hello/:name → SendMessage to SQS
│   └── consumer/         # SQS-triggered Lambda — logs structured JSON
├── packages/
│   └── shared/           # Shared types + queue name constant
├── scripts/
│   ├── env.sh            # AWS endpoint + creds + names
│   ├── setup-queue.sh    # create SQS queue
│   ├── deploy.sh         # deploy both Lambdas + event source mapping + Function URL
│   ├── invoke-producer.sh
│   └── tail-logs.sh      # read /aws/lambda/consumer
├── docker-compose.yml    # floci service on floci-net (FLOCI_HOSTNAME=floci)
├── pnpm-workspace.yaml
├── turbo.json
└── package.json

Prerequisites

  • Node.js 20+
  • pnpm 10+ (corepack enable && corepack prepare pnpm@latest --activate)
  • Docker (Docker Desktop or OrbStack)
  • AWS CLI v2 (brew install awscli)

Run it

# 1) Install dependencies
pnpm install

# 2) Start Floci
pnpm floci:up

# 3) Create the SQS queue
pnpm run setup            # NOTE: `run` is required — `pnpm setup` is reserved

# 4) Build, package, deploy both Lambdas, wire SQS trigger + Function URL
pnpm run deploy

# 5) Trigger producer (sends a message to SQS)
pnpm run invoke alice

# 6) Inspect consumer's CloudWatch logs
pnpm run logs

Stop everything:

pnpm floci:down

Testing with curl

Floci issues a real Lambda Function URL like http://<id>.lambda-url.us-east-1.floci:4566/ — that hostname only resolves inside the floci-net Docker network. From the host, route via localhost:4566 plus a Host: header:

# Auto-resolve the URL ID, then curl through it
HOST=$(AWS_ENDPOINT_URL=http://localhost:4566 AWS_DEFAULT_REGION=us-east-1 \
  AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test \
  aws lambda get-function-url-config --function-name producer \
  --query 'FunctionUrl' --output text | sed -E 's|http://([^/]+)/.*|\1|; s|:4566$||')

# health
curl -sS -H "Host: $HOST" http://localhost:4566/

# enqueue a message
curl -sS -H "Host: $HOST" http://localhost:4566/hello/alice
# → {"enqueued":{"greeting":"Hello, alice!", ...},"messageId":"..."}

# verify the consumer processed it
aws --endpoint-url=http://localhost:4566 logs tail /aws/lambda/consumer --since 5m

What happens end-to-end

  1. producer Hono app receives GET /hello/:name, builds a HelloMessage, and SendMessages to SQS at http://floci:4566/000000000000/hello-queue (the in-container endpoint).
  2. Floci's event source mapping (created by deploy.sh) forwards new SQS messages to the consumer Lambda.
  3. consumer parses the body and console.logs a structured line — Floci writes that to /aws/lambda/consumer in its CloudWatch emulator.
  4. tail-logs.sh (or aws logs tail) reads the latest stream.

Endpoints

Method Path Behaviour
GET / { ok, service, queueUrl, endpoint }
GET /hello/:name enqueues HelloMessage{ enqueued, messageId }

Gotchas

  • pnpm setup is reserved — always use pnpm run setup. Same can apply to other reserved names; prefer pnpm run <script> for project scripts.
  • Function URL hostname: the URL Floci returns is only reachable inside its Docker network; from the host, use the Host: header trick shown above.
  • @app/shared resolution: producer and consumer reference it via workspace:*; esbuild bundles it directly — no separate build step.
  • Consumer uses partial-batch reporting (SQSBatchResponse.batchItemFailures) so a single bad message doesn't reprocess the whole batch.
  • No real AWS resources are created — everything stays inside the Floci container.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors