> ## Documentation index
> Fetch the complete documentation index at: https://context7.com/docs/llms.txt
> Ask it with GET https://context7.com/docs/ask?q=<keywords or question>. Short keywords rank best.
> Use these to discover all available pages before exploring further.
> Feature requests: https://context7.com/docs/resources/feature-requests.md lists what users asked for and how to vote for a request or add one.
> Page rating: `GET https://context7.com/docs/feedback?path=/docs/enterprise/deployment/ecs&helpful={true|false}&comment={comment}` records whether this page helped. The `comment` (URL-encoded, at most 500 characters) says what helped, or what was missing or wrong; a `helpful=false` rating needs it. It is anonymous and needs no key. Comments hold no code, secrets or personal data.

# AWS ECS Deployment

> Run Context7 On-Premise on Amazon ECS with RDS for PostgreSQL, Secrets Manager and Bedrock

This guide runs Context7 On-Premise as several tasks of one Amazon ECS service, on Fargate or EC2. The tasks share state in RDS for PostgreSQL with pgvector. Secrets come from AWS Secrets Manager, and model calls go to AWS Bedrock with the task's IAM role.

It uses the multi-replica setup from [Scaling](/enterprise/deployment/scaling). Read that page first for how replicas share work.

## What you need

- An ECS cluster in a VPC.
- An **RDS for PostgreSQL** instance with **pgvector 0.5.0 or newer**, reachable from the tasks. See [Provision PostgreSQL with pgvector](/enterprise/deployment/scaling#enable-it).
- An **Application Load Balancer** with HTTPS, in front of the service.
- An ECR repository for the Context7 image.
- Bedrock model access in your AWS Region. See [AWS Bedrock](/enterprise/integrations/aws-bedrock).
- A Context7 license key. An offline license (`ctx7off.` prefix) works the same way.

## Step 1: Copy the image to ECR

The image is on `ghcr.io`. Copy it to your ECR repository, so that the tasks pull it from inside AWS:

```bash
LICENSE_KEY="<your-license-key>"
TOKEN=$(curl -s -H "Authorization: Bearer $LICENSE_KEY" \
  https://context7.com/api/v1/license/registry-token | jq -r '.token')
docker login ghcr.io -u x-access-token -p "$TOKEN"

ECR=<account-id>.dkr.ecr.<region>.amazonaws.com
aws ecr get-login-password | docker login --username AWS --password-stdin "$ECR"

docker pull --platform linux/amd64 ghcr.io/context7/enterprise:2.0.6
docker tag ghcr.io/context7/enterprise:2.0.6 "$ECR/context7-enterprise:2.0.6"
docker push "$ECR/context7-enterprise:2.0.6"
```

Use a fixed version tag, not `latest`, so that all tasks run the same version. Repeat this step for each upgrade.

## Step 2: Store the secrets

Create one secret in Secrets Manager with these JSON keys:

| Key | Value |
| --- | --- |
| `LICENSE_KEY` | Your license key. |
| `DATABASE_URL` | `postgres://user:pass@<rds-endpoint>:5432/context7` |
| `ENCRYPTION_KEY` | 64 hex characters from `openssl rand -hex 32`. |

`ENCRYPTION_KEY` encrypts the credentials that Context7 stores, so keep it with your other production secrets. To change it later, see [Rotate the encryption key](/enterprise/deployment/scaling#rotate-the-encryption-key).

ECS reads the secret when it starts a task and passes the values as environment variables. Context7 needs no Secrets Manager access of its own.

## Step 3: Create the IAM roles

- **Task execution role**: ECS uses it to pull the image and read the secret. Attach `AmazonECSTaskExecutionRolePolicy`, and allow `secretsmanager:GetSecretValue` on the secret. If the secret uses a customer managed KMS key, also allow `kms:Decrypt` on that key.
- **Task role**: Context7 uses it to call Bedrock. Allow `bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` on the models you use. See [AWS Bedrock](/enterprise/integrations/aws-bedrock) for inference profile ARNs.

## Step 4: Create the task definition

```json task-definition.json
{
  "family": "context7",
  "requiresCompatibilities": ["FARGATE"],
  "networkMode": "awsvpc",
  "cpu": "2048",
  "memory": "8192",
  "executionRoleArn": "arn:aws:iam::<account-id>:role/context7-execution",
  "taskRoleArn": "arn:aws:iam::<account-id>:role/context7-task",
  "ephemeralStorage": { "sizeInGiB": 50 },
  "containerDefinitions": [
    {
      "name": "context7",
      "image": "<account-id>.dkr.ecr.<region>.amazonaws.com/context7-enterprise:2.0.6",
      "essential": true,
      "portMappings": [{ "containerPort": 3000, "protocol": "tcp" }],
      "environment": [{ "name": "AWS_REGION", "value": "<region>" }],
      "secrets": [
        { "name": "LICENSE_KEY", "valueFrom": "arn:aws:secretsmanager:<region>:<account-id>:secret:context7-AbCdEf:LICENSE_KEY::" },
        { "name": "DATABASE_URL", "valueFrom": "arn:aws:secretsmanager:<region>:<account-id>:secret:context7-AbCdEf:DATABASE_URL::" },
        { "name": "ENCRYPTION_KEY", "valueFrom": "arn:aws:secretsmanager:<region>:<account-id>:secret:context7-AbCdEf:ENCRYPTION_KEY::" }
      ],
      "healthCheck": {
        "command": ["CMD-SHELL", "wget -qO- http://localhost:3000/api/health || exit 1"],
        "interval": 30,
        "timeout": 5,
        "retries": 3,
        "startPeriod": 60
      },
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/context7",
          "awslogs-region": "<region>",
          "awslogs-stream-prefix": "context7"
        }
      }
    }
  ]
}
```

- Each task keeps source clones and agent state in `/data`. With `DATABASE_URL` set, this is scratch space, so task storage is sufficient and you do not need EFS. Increase `ephemeralStorage` if you index large repositories.
- Do not set `AWS_ACCESS_KEY_ID` or `AWS_SECRET_ACCESS_KEY`. Context7 uses the task role.
- On EC2 launch type, remove `requiresCompatibilities` and `ephemeralStorage`, and give the instances enough disk for `/data`.

## Step 5: Create the service

1. Create a target group with target type `ip`, protocol HTTP and port `3000`. Set the health check path to `/api/ready`.
2. Add an HTTPS listener on the load balancer that forwards to the target group.
3. Create the service with two or more tasks, in private subnets, attached to the target group.
4. Allow the task security group to reach RDS on port 5432, and to reach Bedrock.

Without a NAT gateway, the tasks need VPC endpoints for these AWS services:

| Endpoint | Purpose |
| --- | --- |
| `com.amazonaws.<region>.ecr.api` and `com.amazonaws.<region>.ecr.dkr` | Pull the image |
| `com.amazonaws.<region>.s3` (gateway) | Pull the image layers |
| `com.amazonaws.<region>.secretsmanager` | Read the secret |
| `com.amazonaws.<region>.logs` | Send the logs |
| `com.amazonaws.<region>.bedrock-runtime` | Call the models |

Without internet access, also use an offline license. See [Outbound connections](/enterprise/security/outbound-connections).

`/api/ready` returns `200` only when the task can reach the database, so the load balancer sends traffic only to ready tasks. The tasks accept each other's sessions, so you do not need sticky sessions.

## Step 6: Finish setup

Open the load balancer address in your browser and complete the setup wizard. Select **AWS Bedrock** for the models and leave the **API Key** field blank, so that Context7 uses the task role. See [AWS Bedrock](/enterprise/integrations/aws-bedrock).

Then configure sign-in, for example with [SAML SSO](/enterprise/security/saml-sso).

## Upgrade

Copy the new version to ECR (step 1), register a new task definition revision with the new image tag, and update the service. ECS replaces the tasks one by one.

## Network access

| Destination | Purpose |
| --- | --- |
| RDS endpoint, port 5432 | Database and vectors |
| `bedrock-runtime.<region>.amazonaws.com` | Models |
| `context7.com` | License check. Not needed with an offline license. |
| Your Git hosts and documentation sites | Indexing |

For the full list, see [Outbound connections](/enterprise/security/outbound-connections).
