Skip to content

About

Production LangGraph agent on AWS ECS Fargate — full CI/CD: lint → test → Docker → ECR → ECS, zero-downtime deploys

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

AgentOps-Deploy

Production LangGraph agent on AWS ECS Fargate — full CI/CD: lint → test → Docker → ECR → ECS. Zero-downtime deploys. Every git push ships to production automatically.

LangGraph Docker AWS ECS GitHub Actions FastAPI


Why This Repo Exists

Most GenAI engineers can build agents. Few can ship them to production. This repo is a production deployment template — ECS Fargate, zero-downtime rolling updates, automated CI/CD — ready to clone and adapt for any LangGraph agent.


CI/CD Pipeline

Developer pushes to main branch
            │
            ▼
┌───────────────────────────────────────────────────────────┐
│                  GitHub Actions Workflow                   │
│                                                           │
│  Step 1 — Lint                                            │
│  ┌─────────────────────────────────────────────────────┐  │
│  │  ruff check .                                       │  │
│  │  → catches style issues, unused imports, bad syntax │  │
│  └───────────────────────── ✅ PASS ───────────────────┘  │
│                                                           │
│  Step 2 — Test                                            │
│  ┌─────────────────────────────────────────────────────┐  │
│  │  pytest tests/ -v                                   │  │
│  │  → runs unit tests for agents + API endpoints       │  │
│  └───────────────────────── ✅ PASS ───────────────────┘  │
│                                                           │
│  Step 3 — Docker Build                                    │
│  ┌─────────────────────────────────────────────────────┐  │
│  │  docker build --platform linux/amd64 -t app:$SHA .  │  │
│  │  → multi-stage build, ~180MB final image            │  │
│  └───────────────────────── ✅ PASS ───────────────────┘  │
│                                                           │
│  Step 4 — Push to ECR                                     │
│  ┌─────────────────────────────────────────────────────┐  │
│  │  aws ecr get-login-password | docker login ...      │  │
│  │  docker push $ECR_URI:$SHA                          │  │
│  └───────────────────────── ✅ PASS ───────────────────┘  │
│                                                           │
│  Step 5 — Deploy to ECS                                   │
│  ┌─────────────────────────────────────────────────────┐  │
│  │  aws ecs update-service                             │  │
│  │    --force-new-deployment                           │  │
│  │  → rolling update, zero downtime                   │  │
│  └───────────────────────── ✅ PASS ───────────────────┘  │
│                                                           │
│  Total pipeline time: ~3 minutes                          │
└───────────────────────────────────────────────────────────┘
            │
            ▼
   ECS Fargate Task Running New Image
   FastAPI + LangGraph Agent — Live

System Architecture

┌─────────────────────────────────────────────────────────────────┐
│                        AWS INFRASTRUCTURE                        │
│                                                                 │
│  ┌──────────────────────────────────────────────────────────┐   │
│  │                Application Load Balancer                 │   │
│  │         yourdomain.com/api  →  ECS Fargate Task          │   │
│  └────────────────────────────┬─────────────────────────────┘   │
│                               │                                  │
│                               ▼                                  │
│  ┌────────────────────────────────────────────────────────────┐  │
│  │                  ECS Fargate Task                          │  │
│  │                                                            │  │
│  │   ┌─────────────────────────────────────────────────┐     │  │
│  │   │              FastAPI App (port 8000)            │     │  │
│  │   │                                                 │     │  │
│  │   │   POST /run     →  triggers agent pipeline      │     │  │
│  │   │   GET  /health  →  liveness check               │     │  │
│  │   │   GET  /docs    →  Swagger UI                   │     │  │
│  │   └──────────────────────┬──────────────────────────┘     │  │
│  │                          │                                 │  │
│  │                          ▼                                 │  │
│  │   ┌─────────────────────────────────────────────────┐     │  │
│  │   │          LangGraph Multi-Agent Pipeline         │     │  │
│  │   │                                                 │     │  │
│  │   │   ┌─────────────────┐   ┌──────────────────┐   │     │  │
│  │   │   │  Research Agent │   │   Writer Agent   │   │     │  │
│  │   │   │                 │   │                  │   │     │  │
│  │   │   │ • web search    │   │ • synthesize     │   │     │  │
│  │   │   │ • data gather   │──►│ • format output  │   │     │  │
│  │   │   │ • fact check    │   │ • save to S3     │   │     │  │
│  │   │   └─────────────────┘   └──────────────────┘   │     │  │
│  │   └─────────────────────────────────────────────────┘     │  │
│  └────────────────────────────────────────────────────────────┘  │
│                               │                                  │
│                 ┌─────────────┴──────────────┐                   │
│                 ▼                            ▼                   │
│  ┌──────────────────────┐      ┌───────────────────────────┐     │
│  │      AWS ECR         │      │         AWS S3            │     │
│  │  Docker image store  │      │  Agent input/output files │     │
│  │  Tagged by git SHA   │      │  Research artifacts       │     │
│  └──────────────────────┘      └───────────────────────────┘     │
└─────────────────────────────────────────────────────────────────┘

GitHub Actions reads secrets → authenticates AWS → deploys new image

Zero-Downtime Deployment Flow

Old Task (v1) Running
        │
        │   aws ecs update-service --force-new-deployment
        │
        ▼
New Task (v2) starts
        │
        ▼
ECS waits for health check to pass
        │   GET /health → 200 OK
        ▼
ALB routes traffic to New Task (v2)
        │
        ▼
Old Task (v1) drains connections → terminates
        │
        ▼
Only New Task (v2) running
Zero dropped requests during transition

Tech Stack

Layer Technology Role
Agent Framework LangGraph, LangChain Multi-agent orchestration
LLM OpenAI GPT-4o / Groq Research + writing
API FastAPI REST endpoint, Swagger UI
Container Docker (multi-stage) Reproducible builds
Registry AWS ECR Private Docker image store
Compute AWS ECS Fargate Serverless container execution
Storage AWS S3 Agent artifact storage
CI/CD GitHub Actions Automated deploy pipeline
Testing pytest Unit + integration tests
Linting ruff Code quality enforcement

Project Structure

AgentOps-Deploy/
├── .github/
│   └── workflows/
│       └── deploy.yml          # Full CI/CD pipeline definition
├── app/
│   ├── agents/
│   │   ├── research_agent.py   # Searches + gathers information
│   │   └── writer_agent.py     # Synthesizes and formats output
│   ├── graph/
│   │   └── pipeline.py         # LangGraph StateGraph definition
│   ├── api/
│   │   └── routes.py           # FastAPI endpoints
│   └── main.py                 # App entrypoint
├── tests/
│   ├── test_agents.py          # Agent unit tests
│   └── test_api.py             # API endpoint tests
├── infra/
│   └── task-definition.json    # ECS task definition (CPU, memory, env)
├── Dockerfile                  # Multi-stage production build
├── docker-compose.yml          # Local dev environment
├── requirements.txt
└── .env.example

Quick Start

Local (Docker)

git clone https://github.com/iampriyabrat14/AgentOps-Deploy
cd AgentOps-Deploy
cp .env.example .env          # fill in your keys
docker-compose up --build
  • API: http://localhost:8000
  • Swagger: http://localhost:8000/docs
  • Health: http://localhost:8000/health

Environment Variables

OPENAI_API_KEY=your_key
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_key
AWS_REGION=ap-south-1
S3_BUCKET_NAME=agentops-deploy-bucket

GitHub Actions Secrets Required

Add these in your repo Settings → Secrets → Actions:

Secret Purpose
AWS_ACCESS_KEY_ID ECR push + ECS deploy
AWS_SECRET_ACCESS_KEY ECR push + ECS deploy
OPENAI_API_KEY LLM calls in agent

AWS Infrastructure Setup

1. Create ECR repository
   aws ecr create-repository --repository-name agentops-deploy

2. Create ECS cluster
   aws ecs create-cluster --cluster-name agentops-cluster

3. Register task definition
   aws ecs register-task-definition --cli-input-json file://infra/task-definition.json

4. Create ECS service
   aws ecs create-service \
     --cluster agentops-cluster \
     --service-name agentops-service \
     --task-definition agentops-task \
     --desired-count 1 \
     --launch-type FARGATE

5. Push first image + trigger deploy
   git push origin main  ← GitHub Actions handles the rest

Interview Talking Points

Q: Why ECS Fargate over EC2?

Fargate is serverless — no EC2 instances to patch or right-size. You define CPU/memory in the task definition, AWS handles the rest. For agents with variable load, it's simpler and often cheaper.

Q: How do you handle secrets in production?

All secrets are stored in GitHub Actions encrypted secrets, injected as environment variables into the ECS task at runtime via the task definition. Nothing hardcoded, nothing in the image.

Q: What happens if a deploy fails?

ECS waits for the new task's health check (GET /health → 200) before routing traffic. If it never passes, ECS stops the deploy and the old task keeps running. Rolling updates mean zero traffic disruption either way.


Roadmap

  • Add LangSmith tracing
  • Add pgvector memory layer
  • Terraform for infrastructure-as-code
  • Auto-scaling ECS tasks based on queue depth
  • Multi-region deployment

Connect

Priyabrat Dalbehera — AI Engineer | Building production GenAI systems

LinkedIn Portfolio GitHub Email

About

Production LangGraph agent on AWS ECS Fargate — full CI/CD: lint → test → Docker → ECR → ECS, zero-downtime deploys

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages