Guide · AWS App Runner · MCP Server Deployment

AWS App Runner for MCP Servers — Deploy, Health Checks, and IAM Instance Role

AWS App Runner is a fully managed container service that builds, deploys, and scales your MCP HTTP server without requiring you to manage infrastructure. App Runner handles TLS certificate provisioning, load balancing, health checks, and automatic scaling — including scaling to zero when there's no traffic (cutting costs to near-zero for low-traffic MCP servers). For MCP developers who want a production-ready HTTPS endpoint without the operational overhead of ECS or Kubernetes, App Runner is often the right deployment target. This guide covers source-based and image-based deployments, MCP-specific health check configuration, IAM instance role setup for calling other AWS services from tool handlers, and common production pitfalls.

TL;DR

App Runner runs any container or Node.js source repo as a managed HTTPS service. For MCP servers: set port: 3000 (or whatever your server binds to), configure a /health endpoint that returns HTTP 200, and attach an instance role (IAM role) to allow your tool handlers to call DynamoDB, S3, Secrets Manager, or other AWS services. Use the image-based path (ECR) for Node.js MCP servers — it gives you full control over the runtime and cold-start behaviour. Set cpu: "0.25 vCPU" and memory: "0.5 GB" for small MCP servers; bump up if tool handlers do CPU-heavy work (parsing, embedding).

Source-based vs image-based deployment

App Runner supports two deployment modes:

ModeSourceBuild stepBest for
Source-basedGitHub repositoryApp Runner runs npm install && npm run build then npm startSimple Node.js servers; no Docker expertise needed
Image-basedAmazon ECR (private) or ECR PublicNone — image is pre-built; App Runner just pulls and runsProduction MCP servers; reproducible builds; native dependencies

For most MCP server use cases, the image-based path is recommended. It gives you:

Dockerfile for an MCP HTTP server

Use a multi-stage Dockerfile to keep the production image small:

# Stage 1: build
FROM node:20-slim AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build   # e.g., tsc -p tsconfig.json

# Stage 2: production runtime
FROM node:20-slim AS runner
WORKDIR /app
ENV NODE_ENV=production
# Copy only production dependencies + compiled output
COPY package*.json ./
RUN npm ci --omit=dev
COPY --from=builder /app/dist ./dist

# App Runner requires the container to listen on a specific port
# (configured in the App Runner service; typically 8080 or 3000)
EXPOSE 8080

CMD ["node", "dist/index.js"]

Push the image to ECR before creating the App Runner service:

# Create ECR repository
aws ecr create-repository --repository-name my-mcp-server --region us-east-1

# Authenticate Docker to ECR
aws ecr get-login-password --region us-east-1 \
  | docker login --username AWS \
      --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com

# Build and push
docker build -t my-mcp-server .
docker tag my-mcp-server:latest \
  123456789012.dkr.ecr.us-east-1.amazonaws.com/my-mcp-server:latest
docker push \
  123456789012.dkr.ecr.us-east-1.amazonaws.com/my-mcp-server:latest

Health check endpoint

App Runner requires a health check endpoint. It sends HTTP GET requests to a configurable path and considers the instance healthy only when it receives HTTP 200. If health checks fail, App Runner terminates the instance and starts a new one.

Add a /health route to your MCP server:

// In your HTTP server setup (Express, Fastify, Hono, or plain http module)
// alongside the MCP SSE/streamable-HTTP handler:

import express from "express";
const app = express();

// Health check — App Runner polls this every 10–30 seconds
app.get("/health", (_req, res) => {
  res.json({ status: "ok", uptime: process.uptime() });
});

// MCP streamable HTTP transport
app.post("/mcp", mcpHandler);
app.get("/mcp/sse", mcpSseHandler);  // if using SSE transport

app.listen(8080, () => console.log("MCP server listening on :8080"));

Keep the health check handler lightweight — do not make database calls or external HTTP requests inside it. App Runner's health check timeout is 5 seconds by default; a slow health check under load can cause false-positive failures and cascading restarts.

If your MCP server uses a startup initialization phase (loading a model, seeding a cache), return HTTP 503 until initialization is complete so App Runner does not route traffic to an unready instance:

let isReady = false;

async function initializeServer() {
  await loadModels();        // e.g., load embedding model
  await warmupConnections(); // e.g., establish DB connection pool
  isReady = true;
}

app.get("/health", (_req, res) => {
  if (!isReady) {
    return res.status(503).json({ status: "starting" });
  }
  res.json({ status: "ok" });
});

initializeServer();

Creating the App Runner service (AWS CLI)

aws apprunner create-service \
  --service-name my-mcp-server \
  --source-configuration '{
    "ImageRepository": {
      "ImageIdentifier": "123456789012.dkr.ecr.us-east-1.amazonaws.com/my-mcp-server:latest",
      "ImageConfiguration": {
        "Port": "8080",
        "RuntimeEnvironmentVariables": {
          "NODE_ENV": "production",
          "AWS_REGION": "us-east-1"
        }
      },
      "ImageRepositoryType": "ECR"
    },
    "AutoDeploymentsEnabled": true
  }' \
  --instance-configuration '{
    "Cpu": "0.25 vCPU",
    "Memory": "0.5 GB",
    "InstanceRoleArn": "arn:aws:iam::123456789012:role/AppRunnerMCPInstanceRole"
  }' \
  --health-check-configuration '{
    "Protocol": "HTTP",
    "Path": "/health",
    "Interval": 10,
    "Timeout": 5,
    "HealthyThreshold": 1,
    "UnhealthyThreshold": 5
  }' \
  --region us-east-1

When AutoDeploymentsEnabled is true, App Runner monitors your ECR repository and automatically deploys a new revision whenever you push a new image with the same tag (:latest). For production deployments, use immutable tags (e.g., the Git SHA) and trigger deployments explicitly to avoid accidental rollouts.

IAM instance role

The InstanceRoleArn in the instance configuration is the IAM role assumed by the running containers. Use this to grant your MCP tool handlers access to other AWS services. App Runner automatically injects temporary credentials into the container via the instance metadata endpoint.

# Create the trust policy for App Runner tasks
cat > trust-policy.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "tasks.apprunner.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
EOF

aws iam create-role \
  --role-name AppRunnerMCPInstanceRole \
  --assume-role-policy-document file://trust-policy.json

# Attach the permissions your MCP tools need
aws iam put-role-policy \
  --role-name AppRunnerMCPInstanceRole \
  --policy-name MCPToolPermissions \
  --policy-document '{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "dynamodb:GetItem",
          "dynamodb:PutItem",
          "dynamodb:Query",
          "dynamodb:UpdateItem"
        ],
        "Resource": "arn:aws:dynamodb:us-east-1:ACCOUNT:table/mcp-data"
      },
      {
        "Effect": "Allow",
        "Action": [
          "secretsmanager:GetSecretValue"
        ],
        "Resource": "arn:aws:secretsmanager:us-east-1:ACCOUNT:secret:mcp/*"
      },
      {
        "Effect": "Allow",
        "Action": [
          "s3:GetObject",
          "s3:PutObject"
        ],
        "Resource": "arn:aws:s3:::mcp-bucket/*"
      }
    ]
  }'

The AWS SDK automatically picks up these credentials from the IMDS endpoint (no explicit credential configuration needed in your Node.js code). Do not hard-code AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables — the instance role is more secure and the credentials rotate automatically.

Environment variables and secrets

App Runner supports two ways to inject configuration into your containers:

  1. Plain environment variables — set directly in RuntimeEnvironmentVariables. Visible in the App Runner console and in CloudTrail. Use for non-sensitive config like NODE_ENV, PORT, AWS_REGION.
  2. Secrets Manager / Parameter Store references — App Runner resolves these at deploy time and injects the value as an environment variable. The secret value is not visible in the console. Use for API keys, database passwords, signing secrets.
aws apprunner update-service \
  --service-arn arn:aws:apprunner:us-east-1:ACCOUNT:service/my-mcp-server/SERVICE_ID \
  --source-configuration '{
    "ImageRepository": {
      "ImageIdentifier": "123456789012.dkr.ecr.us-east-1.amazonaws.com/my-mcp-server:latest",
      "ImageConfiguration": {
        "Port": "8080",
        "RuntimeEnvironmentVariables": {
          "NODE_ENV": "production"
        },
        "RuntimeEnvironmentSecrets": {
          "DATABASE_URL": "arn:aws:secretsmanager:us-east-1:ACCOUNT:secret:mcp/database-url-AbCdEf",
          "API_KEY": "arn:aws:ssm:us-east-1:ACCOUNT:parameter/mcp/api-key"
        }
      },
      "ImageRepositoryType": "ECR"
    }
  }'

The instance role must have secretsmanager:GetSecretValue or ssm:GetParameters permission for the secret/parameter ARNs used in RuntimeEnvironmentSecrets. See App Runner secrets management deep dive for rotation and versioning patterns.

apprunner.yaml for source-based deployments

When using the source-based (GitHub) deployment mode, place an apprunner.yaml in your repository root:

version: 1.0
runtime: nodejs20
build:
  commands:
    build:
      - npm ci
      - npm run build
run:
  command: node dist/index.js
  network:
    port: 8080
    env: PORT
  env:
    - name: NODE_ENV
      value: production
    - name: DATABASE_URL
      value-from: arn:aws:secretsmanager:us-east-1:ACCOUNT:secret:mcp/database-url

Source-based deployments use the build role (not the instance role) during the build phase. If your build scripts need AWS access (e.g., pulling private npm packages from CodeArtifact), grant those permissions to the build role, not the instance role.

Deployment and rollback

App Runner creates a new revision for every deployment. If a new revision's health checks fail, App Runner does not route traffic to it and you can roll back to the previous revision:

# List revisions for a service
aws apprunner list-operations \
  --service-arn arn:aws:apprunner:us-east-1:ACCOUNT:service/my-mcp-server/SERVICE_ID

# Roll back to a previous revision
aws apprunner start-deployment \
  --service-arn arn:aws:apprunner:us-east-1:ACCOUNT:service/my-mcp-server/SERVICE_ID

Deployment to App Runner takes 1–3 minutes (pull image, start new instances, health check, traffic shift, terminate old instances). There is no zero-downtime guarantee during deployments unless you configure a minimum of 2 instances — with 1 instance, there is a brief gap between the old instance stopping and the new one passing health checks.

Pricing model

App Runner charges on two dimensions:

DimensionRate (us-east-1)Notes
Provisioned instances (active)~$0.064/vCPU/hr + ~$0.007/GB/hrCharged when instances are running (not paused)
Active request processing~$0.000009/reqCharged per request regardless of instance state
Automatic scaling to zeroNo instance cost while pausedInstance pauses after ~1 min idle; cold start adds 1–10s to first request

For a low-traffic MCP server (e.g., personal Claude Desktop extension), the cost is typically under $5/month with auto-scaling enabled. For 24/7 availability without cold starts, set minSize: 1 in the auto-scaling configuration — this costs about $5–10/month for the smallest instance size. See App Runner auto-scaling configuration for the full tradeoff analysis.

Common errors and fixes

ErrorCauseFix
Service stuck in OPERATION_IN_PROGRESSHealth checks failing during initial deploymentCheck CloudWatch logs (auto-created log group /aws/apprunner/SERVICE/application); ensure /health returns 200 before full init
CONTAINER_EXITED immediately after startApplication crashes on startup (missing env var, port conflict)Test the Docker image locally with docker run -p 8080:8080 --env-file .env image:tag
HTTP 503 on requests after deploymentNew revision failed health checks; traffic still on old revisionCheck if old revision is still running; App Runner automatically keeps old revision if new one fails
IAM permission errors in tool handlersInstance role not attached or missing required actionCheck InstanceRoleArn is set in service config; add missing IAM actions to the role policy
Cold start latency (5–15s) on first requestInstance was paused (auto-scaled to zero)Set minSize: 1 to keep at least one warm instance; or accept cold starts for low-traffic servers
ECR pull errorsApp Runner access role lacks ECR read permissionsAttach AWSAppRunnerServicePolicyForECRAccess managed policy to the App Runner access role (separate from instance role)

Related guides