Skip to content
Start free

AWS ECS

Open in ClaudeOpen in ChatGPT

Our Terraform module runs DocSpring Enterprise in your own AWS account on Amazon ECS with Fargate, so there are no servers or Kubernetes cluster to manage. It works with Terraform or OpenTofu 1.6 or later. The module and its full guide are in the aws-ecs folder of DocSpring/docspring-enterprise.

  • A VPC with public and private subnets across two or three availability zones, or it uses your existing VPC.
  • RDS PostgreSQL 17, encrypted, with 7 days of point-in-time recovery.
  • ElastiCache Valkey (compatible with Redis), with TLS.
  • A private, versioned, encrypted S3 bucket for files.
  • An Application Load Balancer with HTTPS, using your ACM certificate or one it creates in your Route 53 zone.
  • The web, worker and worker_gj services on Fargate, on Graviton (arm64) by default, with autoscaling.
  • The release command, and the three scheduled tasks on EventBridge Scheduler.
  • The secrets in Secrets Manager, and IAM roles that can reach only what DocSpring needs.

With the defaults, it costs about $280 to $300 a month in us-east-1, plus data transfer. The module’s README breaks that down.

  • Terraform or OpenTofu 1.6 or later, and the AWS CLI v2, signed in with IAM Identity Center or a role that can create the resources above.
  • Your license key and Docker Hub credentials, which we email you.
  • A DNS name for DocSpring, with a Route 53 hosted zone or an ACM certificate for it.
  • An email provider.
  1. Copy the module’s example folder, copy terraform.tfvars.example to terraform.tfvars, and fill it in: the region, your domain, the image version, your license key, the Docker Hub credentials and the first admin’s email address and password. Keep terraform.tfvars out of version control.
  2. Store the Terraform state in an encrypted S3 bucket that only your administrators can read: it holds the secrets the module generates, including the encryption key.
  3. Run terraform init and terraform apply. It takes 15 to 20 minutes, mostly for RDS and ElastiCache.
  4. Run the deploy command that terraform output deploy_command prints. It runs the release command, which creates the database schema and the admin user, then starts the services on that release and waits until they’re healthy.
  5. Copy DOCSPRING_SUBMISSION_DATA_ENCRYPTION_KEY from the app’s secret in Secrets Manager to somewhere outside AWS, such as your password manager. Without it, the data DocSpring stores can’t be read.

Then open your domain, sign in and change the admin password.

Add settings that aren’t secret to extra_environment, and secret ones, such as an email provider’s token, to extra_secrets. After changing them, run terraform apply and then the deploy command, so the tasks restart with them. The tasks use their IAM role for S3, so there are no access keys to manage.

  1. Read the release notes of the new version.
  2. Set image_tag in terraform.tfvars and run terraform apply. This registers the new release’s task definitions without changing what’s running.
  3. Run the deploy command. It runs the release command on the new release, and only if that succeeds moves the services and then the scheduled tasks to it. If a service’s rollout fails, ECS rolls it back.

To go back to the previous release, set image_tag back, apply and deploy again.

  • Fargate doesn’t let containers add the NET_ADMIN capability, so the containers can’t add their firewall rule for the cloud metadata address, and log a warning at startup. Fargate tasks can’t reach that address anyway: their credentials come from the ECS task role. If your policies require the firewall rule, run the tasks on ECS with EC2 instances instead.
  • Fargate gives a stopping task at most 120 seconds, so a web request that runs longer than that during a deploy is cut off.
  • Fargate doesn’t cache images, so every task that starts pulls the image, including each scheduled task run. An ECR pull-through cache cuts the NAT data charges: the module’s README explains how.
  • For a shell or Rails console in a running task, use ECS Exec: terraform output ecs_exec_command, then run_as_deploy rails console.