Skip to Content
Runlane
Run in productionDeploy to AWS

Prepare for production

Replace the tutorial's public network and temporary settings before real use.

Use this checklist before storing real data. Keep verified TLS, least-privilege access, and a migration step that blocks failed deploys.

A virtual private cloud (VPC) is your AWS network. A subnet is a range of addresses within it. A private subnet has no direct route to an internet gateway. A security group holds network access rules. An IAM role is an AWS identity whose policies grant permissions.

Make the database private

  • Turn off public access for the Amazon RDS Postgres database. Use private subnets in two Availability Zones. Each zone is a separate location within the region. This removes the public connection path. See RDS VPC access.
  • Put the delivery and maintenance Lambda functions in private subnets in that VPC. Add the required network-interface permissions to their roles. Connecting Lambda to a public subnet does not give it internet access. See Lambda VPC networking.
  • Add an SQS interface VPC endpoint with private DNS enabled. An endpoint gives private access to an AWS service. Private DNS makes its normal hostname resolve to private addresses. Let workload security groups reach the endpoint on TCP 443. This lets app code publish to Amazon Simple Queue Service (SQS) without internet access. See SQS private access.
  • Alternatively, route outbound traffic through a NAT gateway. A NAT gateway gives private workloads outbound internet access. Use it when handlers call public APIs as well. Budget for its cost and availability. See private subnet internet access.
  • Replace 0.0.0.0/0 on database port 5432 with security groups for workloads and the migration runner. Include delivery, maintenance, and worker groups. Add a separate group for operator tasks. This limits who can attempt a database connection. See RDS security groups.

Give the container private access

Fargate runs containers without servers for you to manage. Use Amazon Elastic Container Service (ECS) to manage the worker. A task definition describes its image, resources, roles, and settings. Store its image in Amazon Elastic Container Registry (ECR).

  • Move the worker to private subnets and turn off its public IP. Use a NAT gateway or the endpoints below. The worker must still pull its image, send logs, and reach SQS.
  • For a path without NAT, add interface endpoints for ECR API, ECR Docker, CloudWatch Logs, and SQS. Add an S3 gateway endpoint for image layers. CloudWatch stores the logs; S3 stores the image layers used by ECR. Enable private DNS on interface endpoints and allow TCP 443 from the worker. Attach the S3 endpoint to the worker subnet route tables. See ECR endpoint requirements.
  • Add endpoints for Secrets Manager or Systems Manager if your worker reads secrets without NAT. Include any other service the app calls. Endpoint policies and IAM policies must both allow the calls.
  • Keep the task execution role separate from the task role. The execution role pulls images and sends platform logs. The task role grants the app's SQS access. See ECS IAM roles.
  • If you deploy with AWS CDK, narrow the bootstrap deploy role. By default, cdk bootstrap gives CloudFormation's execution role AdministratorAccess, so any CDK stack in that account and region can create any resource. Re-run cdk bootstrap with --cloudformation-execution-policies set to policies that cover only what your stacks create. See CDK bootstrapping.

Keep migrations and operator access working

  • Run npm exec -- runlane adapter postgres migrate as a release step before workloads change. Use a host that can reach the private database, such as a CI/CD runner inside the VPC. Or run a one-off ECS task from an operator image. That image needs the CLI, app config, and installed app packages. Supply the runtime env values and export the CA path before Node starts. Allow the runner through the database security group and keep verified TLS. A migration failure must stop the release. See Postgres migrations.
  • Run operator CLI commands from an in-VPC task, or use ECS Exec. ECS Exec opens a managed session into a running container. Do not reopen RDS to your laptop. This tutorial's minimal image has no Runlane CLI or source config for operators. Build a separate operator image with the CLI, source config, and app code.
  • If using ECS Exec without NAT, add its required Systems Manager messaging endpoint. Grant only the operator and task permissions it needs. Keep an audit log of sessions. Run the deployment checks through this private path.

Protect and rotate credentials

  • Store secrets in Secrets Manager. Or use Systems Manager Parameter Store with SecureString. These services store encrypted secrets. Grant each role access only to the secret it needs. Fetch it before creating the Runlane runtime, or inject it through the platform. See ECS secrets and Lambda secrets.
  • Plan rotation with the app lifecycle. A changed secret leaves old env values and Postgres pools in place. Start new worker tasks to load an injected value. For Lambda, refresh the secret in app code and recreate the runtime, or deploy a new configuration. Drain old processes before retiring old credentials. Test a rotation before relying on it. AWS explains when ECS loads updated secrets.
  • Keep sslmode=verify-full and the RDS CA bundle in all workloads and operator processes. Update the bundle before a CA change. See RDS certificate rotation.

Protect database state

  • Enable Multi-AZ. This keeps a standby in another Availability Zone for failover.
  • Set backup retention to match your recovery needs. Test restoring into a separate database. A backup is useful only if you can recover it.
  • Turn on deletion protection. Require a final snapshot. Review teardown commands so an app cleanup cannot silently delete task history. See RDS deletion rules.

Bound load and connections

  • Set a connection budget for all processes. Count Lambdas, workers, producers, migrations, and operators. Each runtime owns a pool. Warm Lambda processes may retain connections after a call. Follow Postgres connection budgets, Lambda sizing, and worker sizing.
  • Evaluate RDS Proxy to share backend connections. Test its behavior with your workload. It does not remove the need for a connection budget.
  • Add reserved concurrency when your account quota allows it. This caps concurrent Lambda calls to the function. Keep the SQS event source cap within that reservation. An event source mapping polls SQS and invokes Lambda. The tutorial caps this mapping at two concurrent calls, but leaves function reservations unset. New accounts may lack enough quota to reserve capacity. See reserved concurrency and SQS scaling.
  • Give the worker time to drain before ECS stops it. The tutorial's 60-second stop timeout fits the default shutdownGrace (contractDefaults.worker.shutdownGrace, 25 seconds today). If you raise shutdownGrace, raise the stop timeout too, up to Fargate's 120-second limit. Keep handlers safe to retry after a forced stop; see make side effects safe to repeat. See ECS stop timeout and allow time for worker shutdown.
  • Keep scheduled tasks on standard queues. SQS FIFO queues can't delay single messages, so a scheduled run on a FIFO queue can start up to one maintenance interval late. See give maintenance its own process.

Make tasks safe to retry

  • Put every database write, payment, email, and API call in a step, and pass the step's token as an idempotency key. A run can repeat a side effect after a crash or timeout. See make side effects safe to repeat.
  • Test it: stop a worker during a side effect, and confirm the next attempt does not repeat it.

Add alarms and recovery checks

A dead-letter queue (DLQ) holds messages after repeated delivery failures. EventBridge Scheduler is the timer service that invokes maintenance.

  • Alarm on DLQ depth above zero. Keep failed messages for inspection and redrive only after fixing the cause. During a long rolling deploy, messages for a new task can land here while old consumers hand them back; maintenance republishes those runs, so check for worker_task_missing before treating them as lost.
  • Alarm on the oldest message age for each work queue. A growing age can mean the consumer is stopped or lacks capacity.
  • Alarm on Lambda errors and throttles. Also check failed delivery results: partial SQS batch failures may not raise the Lambda Errors metric.
  • Alarm when the worker's running task count falls below its desired count. Also inspect repeated task restarts.
  • Alarm on worker_task_missing warnings. They mean a worker has no code for a queued run's task, so that run waits. See change tasks safely.
  • Alarm when maintenance fails. Also track missed Scheduler calls. Track failed Scheduler target calls and confirm a delayed test run completes. A healthy delivery function does not prove maintenance works.

Use SQS metrics, Lambda metrics, ECS Container Insights, and Scheduler metrics. Pick thresholds and time windows from your service's needs.

Plan later releases

Follow Upgrade Runlane for package and storage changes. Follow change tasks safely to pick the right tool for each task change, and deploy task changes for patch details and drain steps. Keep old task ids and payload support until saved work has finished.

On this page