Skip to main content

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. 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.
  • 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.
  • 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:

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:

KeyValue
LICENSE_KEYYour license key.
DATABASE_URLpostgres://user:pass@<rds-endpoint>:5432/context7
ENCRYPTION_KEY64 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.

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 for inference profile ARNs.

Step 4: Create the task definition#

task-definition.json
  • 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:

EndpointPurpose
com.amazonaws.<region>.ecr.api and com.amazonaws.<region>.ecr.dkrPull the image
com.amazonaws.<region>.s3 (gateway)Pull the image layers
com.amazonaws.<region>.secretsmanagerRead the secret
com.amazonaws.<region>.logsSend the logs
com.amazonaws.<region>.bedrock-runtimeCall the models

Without internet access, also use an offline license. See 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.

Then configure sign-in, for example with 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#

DestinationPurpose
RDS endpoint, port 5432Database and vectors
bedrock-runtime.<region>.amazonaws.comModels
context7.comLicense check. Not needed with an offline license.
Your Git hosts and documentation sitesIndexing

For the full list, see Outbound connections.