Skip to main content

AWS Infrastructure

SuperBox backend runs on AWS with a highly available, scalable architecture.

Compute

ECS Fargate for containerized Go API

Database

RDS PostgreSQL with Multi-AZ

Cache

ElastiCache Redis cluster

Storage

S3 for MCP server packages

Functions

Lambda for MCP execution

CDN

CloudFront for distribution

Prerequisites

1

AWS Account

Create an AWS account at aws.amazon.com
2

AWS CLI

Install and configure AWS CLI:
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

# Configure credentials
aws configure
Enter your AWS credentials:
AWS Access Key ID: your_access_key
AWS Secret Access Key: your_secret_key
Default region name: ap-south-1
Default output format: json
3

Terraform

Install Terraform for infrastructure as code:
# Download Terraform
wget https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
unzip terraform_1.6.0_linux_amd64.zip
sudo mv terraform /usr/local/bin/

# Verify installation
terraform version
4

Docker

Install Docker for containerization:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER

Infrastructure Setup with Terraform

Project Structure

terraform/
├── main.tf               # Main configuration
├── variables.tf          # Input variables
├── outputs.tf            # Output values
├── vpc.tf               # VPC configuration
├── rds.tf               # Database configuration
├── elasticache.tf       # Redis configuration
├── ecs.tf               # ECS cluster and services
├── alb.tf               # Application Load Balancer
├── s3.tf                # S3 buckets
├── lambda.tf            # Lambda functions
├── cloudfront.tf        # CDN configuration
└── iam.tf               # IAM roles and policies

Initialize Infrastructure

variable "aws_region" {
  description = "AWS region"
  default     = "ap-south-1"
}

variable "environment" {
  description = "Environment name"
  default     = "production"
}

variable "app_name" {
  description = "Application name"
  default     = "superbox"
}

variable "db_username" {
  description = "Database master username"
  type        = string
  sensitive   = true
}

variable "db_password" {
  description = "Database master password"
  type        = string
  sensitive   = true
}

variable "jwt_secret" {
  description = "JWT secret key"
  type        = string
  sensitive   = true
}

Deploy Infrastructure

1

Initialize Terraform

cd terraform
terraform init
2

Create terraform.tfvars

aws_region  = "ap-south-1"
environment = "production"
app_name    = "superbox"
db_username = "superbox_admin"
db_password = "change-this-password"
jwt_secret  = "your-jwt-secret-key"
Store sensitive values in AWS Secrets Manager or use Terraform Cloud for secure variable management.
3

Plan Infrastructure

terraform plan -out=tfplan
Review the planned changes carefully.
4

Apply Infrastructure

terraform apply tfplan
This will create:
  • VPC with public/private subnets
  • RDS PostgreSQL database
  • ElastiCache Redis cluster
  • ECS cluster and services
  • Application Load Balancer
  • S3 buckets
  • Lambda functions
  • CloudFront distribution

Docker Container Build

Dockerfile

# Build stage
FROM golang:1.22-alpine AS builder

WORKDIR /app

# Install dependencies
RUN apk add --no-cache git

# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o main cmd/server/main.go

# Runtime stage
FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/

# Copy binary from builder
COPY --from=builder /app/main .

# Copy migrations
COPY --from=builder /app/migrations ./migrations

EXPOSE 8080

CMD ["./main"]

Build and Push to ECR

Create ECR Repository
aws ecr create-repository \
  --repository-name superbox-api \
  --region us-east-1

CI/CD Pipeline

GitHub Actions Workflow

.github/workflows/deploy.yml
name: Deploy to AWS

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  AWS_REGION: us-east-1
  ECR_REPOSITORY: superbox-api
  ECS_CLUSTER: superbox-cluster
  ECS_SERVICE: superbox-api
  CONTAINER_NAME: api

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: "1.22"

      - name: Run tests
        run: go test ./... -v -cover

      - name: Run linter
        uses: golangci/golangci-lint-action@v4
        with:
          version: latest

  build-and-deploy:
    needs: test
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'

    steps:
      - uses: actions/checkout@v4

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ env.AWS_REGION }}

      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v2

      - name: Build, tag, and push image to Amazon ECR
        id: build-image
        env:
          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
          IMAGE_TAG: ${{ github.sha }}
        run: |
          docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
          docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
          docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
          docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
          echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT

      - name: Download task definition
        run: |
          aws ecs describe-task-definition \
            --task-definition superbox-api \
            --query taskDefinition > task-definition.json

      - name: Fill in the new image ID in the Amazon ECS task definition
        id: task-def
        uses: aws-actions/amazon-ecs-render-task-definition@v1
        with:
          task-definition: task-definition.json
          container-name: ${{ env.CONTAINER_NAME }}
          image: ${{ steps.build-image.outputs.image }}

      - name: Deploy Amazon ECS task definition
        uses: aws-actions/amazon-ecs-deploy-task-definition@v1
        with:
          task-definition: ${{ steps.task-def.outputs.task-definition }}
          service: ${{ env.ECS_SERVICE }}
          cluster: ${{ env.ECS_CLUSTER }}
          wait-for-service-stability: true

Lambda Deployment

Lambda Function Code

lambda/executor/handler.py
import json
import subprocess
import tempfile
import os
from pathlib import Path

def handler(event, context):
    """
    Execute MCP server tool in isolated Lambda environment
    """
    server_id = event['server_id']
    tool_name = event['tool_name']
    parameters = event.get('parameters', {})

    try:
        # Download server code from S3
        s3_key = f"servers/{server_id}/latest.zip"
        local_path = f"/tmp/{server_id}"

        # Extract and setup
        extract_server(s3_key, local_path)

        # Install dependencies
        install_dependencies(local_path)

        # Execute tool
        result = execute_tool(local_path, tool_name, parameters)

        return {
            'statusCode': 200,
            'body': json.dumps({
                'result': result,
                'duration_ms': context.get_remaining_time_in_millis()
            })
        }

    except Exception as e:
        return {
            'statusCode': 500,
            'body': json.dumps({
                'error': str(e)
            })
        }

Deploy Lambda with Terraform

lambda.tf
resource "aws_lambda_function" "executor" {
  filename      = "lambda-executor.zip"
  function_name = "${var.app_name}-executor"
  role          = aws_iam_role.lambda_exec.arn
  handler       = "handler.handler"
  runtime       = "python3.11"
  timeout       = 30
  memory_size   = 1024

  environment {
    variables = {
      S3_BUCKET = aws_s3_bucket.servers.id
    }
  }

  vpc_config {
    subnet_ids         = aws_subnet.private[*].id
    security_group_ids = [aws_security_group.lambda.id]
  }

  tags = {
    Name        = "${var.app_name}-executor"
    Environment = var.environment
  }
}

Monitoring & Logging

CloudWatch Logs

Centralized logging for all services

CloudWatch Metrics

Custom metrics and alarms

X-Ray Tracing

Distributed tracing

CloudWatch Dashboard

Real-time monitoring

Next Steps