This repo is starter code for the team (split-by-service) option of Project 2: Instrumented & Monitored Cloud Service.
What this repo gives you: two working Node.js/Express services with basic business logic already wired up, so you can spend your 3 days on deployment, instrumentation, dashboards, alerting, and incident response — not on writing CRUD routes.
What this repo does NOT give you (this is your project work — see the TODO comments in each server.js):
- Structured JSON logging
- Custom CloudWatch metrics
- Correlation ID generation and pass-through
- CloudWatch Logs Agent config
- Dashboards, alarms, SNS topics
- Auto-remediation Lambda
- Service map widget
- Cross-service Logs Insights queries
- Injected failure scenarios
Refer back to the main Project 2 spec and the Team Addendum doc for full requirements — this repo only covers the "app" piece.
client
|
v
+-------------------+ +----------------------+
| order-service | -----> | inventory-service |
| (port 3000) | HTTP | (port 3001) |
+-------------------+ +----------------------+
- order-service —
POST /orders,GET /orders/:id,GET /health. On order creation, callsinventory-serviceto reserve stock before confirming the order. - inventory-service —
GET /inventory/:sku,POST /inventory/reserve,GET /health. Maintains in-memory stock levels.
Both services use an in-memory data store (a plain JS object) — no database required. Data resets when the process restarts. This is intentional: you're being graded on observability, not persistence.
ce-project-2-starter-code/
├── README.md (this file)
├── ecosystem.config.js (pm2 process definitions - run both services with one command)
├── order-service/
│ ├── server.js
│ ├── package.json
│ ├── .env.example
│ └── README.md
├── inventory-service/
│ ├── server.js
│ ├── package.json
│ ├── .env.example
│ └── README.md
└── scripts/
└── generate-traffic.sh (basic load generator for testing/verifying metrics)
Requires Node.js 18+ and npm. Check your version first:
node -v
npm -vTerminal 1 — Inventory Service:
cd inventory-service
cp .env.example .env
npm install
npm startYou should see Inventory service listening on port 3001.
Terminal 2 — Order Service:
cd order-service
cp .env.example .env
npm install
npm startYou should see Order service listening on port 3000.
Verify both are healthy:
curl http://localhost:3001/health
curl http://localhost:3000/healthTry placing an order (exercises both services):
curl -X POST http://localhost:3000/orders \
-H "Content-Type: application/json" \
-d '{"sku": "SKU-001", "quantity": 2, "customerId": "cust-1"}'pm2 is a process manager for Node.js — it starts your app, restarts it if it crashes, and keeps it running in the background (so it survives you closing your SSH session). This is what you'll actually use on EC2.
npm install -g pm2
# one-time setup, same as Option A
cd inventory-service && cp .env.example .env && npm install && cd ..
cd order-service && cp .env.example .env && npm install && cd ..
# start both services
pm2 start ecosystem.config.js
pm2 status # confirm both show "online"
pm2 logs # tail both services' logs live (Ctrl+C to stop watching)
pm2 restart order-service # restart just one
pm2 stop all # stop bothTo have both services come back automatically if the EC2 instance reboots:
pm2 save
pm2 startup # then copy/paste and run the command it prints (needs sudo)chmod +x scripts/generate-traffic.sh
./scripts/generate-traffic.shThis sends a mix of valid orders, invalid SKUs, and out-of-stock requests against order-service so you have both success and error traffic to see in your logs and metrics right away.
This starter code is a plain Node.js/Express app, run with pm2 — deploy it to an EC2 instance per the main project spec:
- Launch an EC2 instance (Amazon Linux), install Node.js 18+ and
npm install -g pm2. - Clone this repo onto the instance (or
scpit over). - Follow the same setup as Option B above (
npm installin each service dir,pm2 start ecosystem.config.js,pm2 save && pm2 startup). - Open the security group for ports 3000 and 3001 (or whatever ports you configure) so you can reach the services.
A few notes:
- Each service needs its own deployment target — either two separate EC2 instances, or both running on the same instance under different ports (fine for this project; just update
INVENTORY_SERVICE_URLaccordingly if you split them across two instances, using the private IP of the inventory-service instance). - Both services expose
GET /health— use it for a load balancer / target group health check if you set one up. - Nothing in this repo talks to CloudWatch yet. That's the instrumentation work you'll add per the CloudWatch Agent / SDK setup described in the main project docs.
Both server.js files have // TODO: comments marking exactly where to add:
- Correlation ID middleware (generate/read
X-Correlation-Id, attach toreq, pass it downstream on the inventory call) - Structured JSON logging (replace the placeholder
console.logcalls) - Custom metrics (order count, order value, error rate, latency, stock levels, etc. — see
INSTRUMENTATION.mdguidance in the main spec)
Start with correlation IDs first — the Team Addendum calls this out as the foundation everything else depends on.