rvn-ecs-web / Latest version: 2.10.0
Dependencies and consumers
Every dependency input can be specified manually to reference existing external infrastructure rather than a Ravion module. Set the dependency input tonull and set its mapped inputs directly; see Use existing infrastructure instead of a module reference.
Readme
Rolling deployment success
Rolling deploys always use AWS early success: by default, 100% of desired new tasks must be healthy and old tasks drain in the background. Wait for old tasks to drain selects blocking cleanup. Alarm bake time still applies. The success percentage must be at least Minimum healthy percent; lower the availability floor explicitly before choosing a lower threshold. Remaining tasks scale in the background and deployment rollback monitoring ends at ECS success. Web server ECS service for running an HTTP application behind an ECS cluster load balancer.Overview
The ECS Web Server module creates an ECS service for HTTP traffic in an existing Ravion ECS cluster. Select an ECS cluster, choose how the container image is built or supplied, configure routing and health checks, and Ravion provisions the service, target group, listener rule, IAM roles, security group, ECR repository when needed, and autoscaling settings. The module is intentionally focused on web services behind an Application Load Balancer. It uses the selected ECS cluster to inherit AWS account, region, VPC, subnets, capacity providers, load balancer listeners, and load balancer security groups. Terraform source: ravionhq/modules/compute/ecs_serviceUse cases
Cluster and networking
An ECS cluster is required. The cluster reference supplies the cluster ARN, VPC ID, public and private subnet IDs, load balancer listeners, load balancer security groups, capacity provider names, AWS account, region, and execution environment. Use Public web service when the service should be reachable through the public Application Load Balancer. Turn it off for internal services that should use the private Application Load Balancer. Use Run in private subnets for most production services. Private subnets keep tasks off the public internet and route outbound traffic through NAT or equivalent egress. Turning it off runs tasks in public subnets and assigns public IPs.Build and image options
For Railpack and Dockerfile builds, provide Git repository, Git branch, and optionally Base path. Ravion pushes built images to the service ECR repository and deploys by image digest.
Railpack settings let you optionally pin the Railpack version and override install, build, and start commands. Leave them blank to use Railpack defaults and autodetection.
For Pull from image registry, provide the image repository without the tag. At deploy time, provide the tag to use. Use Registry credentials secret ARN for private registries that require ECS repository credentials.
For Managed ECR repository, Ravion creates and manages the service ECR repository. Push the image from a pipeline
build:image step, then provide its tag or digest at deploy time.
Override the start command
For Dockerfile, Pull from image registry, and Managed ECR repository builds, use Start command (image_start_command) to override the image’s CMD without changing its ENTRYPOINT. Leave it empty to keep the image default.
Set a different command for each service to reuse one Dockerfile for your web app and background workers. Pass each argument as a separate array item, for example image_start_command: ["npm", "run", "start:web"] for the web service and ["npm", "run", "start:worker"] for a worker. For Railpack builds, use Railpack start command instead.
Routing and health checks
The service always attaches to an Application Load Balancer target group. Route traffic with Domain host rules, Path rules, or both. If both host and path rules are empty, Ravion creates a default /* path rule so the listener rule has a valid condition. Use Listener rule priority only when you need a specific ALB rule order; otherwise AWS assigns the next available priority. Health check settings control when the load balancer considers tasks healthy:
Increase the grace period for apps with slow boot times. Keep health check endpoints lightweight and unauthenticated.
Capacity and runtime
Choose one primary Capacity provider:
You can add secondary providers with Also use Fargate, Also use Fargate spot, and Also use EC2. Mixed strategies can reduce cost or increase placement flexibility, but each enabled provider must exist on the selected cluster.
For Fargate and Fargate Spot, App size defaults to 2 vCPU and 4 GB memory. App ephemeral storage uses the AWS default of 20 GiB unless you increase it to 21-200 GiB. For EC2 capacity, App vCPU defaults to 1.5 and App memory in GB defaults to 3.5; leave spare CPU and memory on each EC2 instance for the ECS agent and system processes.
CPU architecture defaults to x86_64 for broad compatibility. Choose ARM64 only when the image and native dependencies support it.
Autoscaling
Autoscaling is enabled by default with one minimum task and three maximum tasks. For production, start with at least two minimum tasks when availability matters. When autoscaling is disabled, Desired tasks controls how many web tasks the ECS service keeps running. To stop the service without deleting it, keep autoscaling enabled and set Minimum tasks and Maximum tasks to 0. ECS scales the running tasks in to 0 while the service, load balancer routing, roles, and image repository stay in place. Deploys while stopped keep the task count at 0. Set the bounds back above 0 to start the service again. Scheduled scaling actions still apply, so remove or adjust any that would raise the bounds while the service should stay stopped.Application configuration
Use Runtime environment variables for plain values, as an array of{name, value} objects. Ravion also sets PORT from Container port.
Use Deploy-provided environment variables to allow a pipeline deploy step to set selected plain values. They cannot replace a Runtime environment variable or Runtime secret, and PORT is reserved for the web service.
Use Runtime secrets for sensitive values. Secrets are injected into the ECS task from SSM Parameter Store or Secrets Manager using name and value_from objects.
Stop timeout (secs) controls how long ECS waits after sending SIGTERM to the app container before sending SIGKILL. The default is 30 secs; Fargate allows up to 120 secs.
Use Build environment variables for values needed during image builds. Values can be plain strings or references loaded from Parameter Store or Secrets Manager. For Dockerfile builds, enable Inject environment variables in Dockerfile to pass those values as Docker build arguments.
Persistent storage
Enable the EFS file system setting, select a Ravion EFS module, and set the EFS mount path. Ravion adds the task volume, mounts it into the app container, attaches the file system’s client security group to the service so NFS traffic is allowed, and mounts through the file system’s access point when one is enabled. Sidecars mount the same file system through their Mount points setting withefs as the source volume.
EFS volumes work with Fargate and EC2 Linux tasks and keep data across task replacement. Transit encryption is enabled by default. Enable EFS IAM authorization to authorize file system access with the task role; the task role must allow elasticfilesystem:ClientMount, plus elasticfilesystem:ClientWrite or elasticfilesystem:ClientRootAccess as needed.
Deployment
Deployment strategy defaults to Rolling. Blue/green, Linear, and Canary use the native ECS traffic-shift controller with production and alternate target groups. The deployment strategy can change between deploys without changing Terraform infrastructure. Deployments update the ECS service task definition with the selected image, generated container definition, awslogs configuration, runtime platform, environment variables, secrets, and capacity-provider-compatible task settings. The deploy-time Image value depends on the build source:
Run pre-deploy command and Run post-deploy command start optional one-off ECS tasks before or after each deployment. These commands use the deployed app image, the app container name, the configured task role and execution role, the selected capacity provider strategy, service subnets, service security groups, runtime environment variables, and runtime secrets. Leave either toggle disabled to skip that hook and hide its settings.
Use pre-deploy commands for work that must complete before the service updates, such as database migrations. Use post-deploy commands for work that should happen after a successful deployment, such as cache warming. Commands are ECS command argument arrays. For shell behavior, use
/bin/sh, -lc, and your shell command as separate arguments.
Hook-specific environment variables are appended to the app container override for the one-off task. Optional hook CPU, memory, ephemeral storage, and timeout settings let release tasks use different resources from the web service without changing the steady-state app task.
Standby validation traffic
For Blue/green, Linear, and Canary deployments, Ravion creates a test listener rule on the same Application Load Balancer listener as the production rule. During the test traffic stage, requests that match the service’s normal Domain host rules and Path rules and include the standby selector route to the standby, or green, task set on the alternate target group. By default, the standby selector is the query parameter__x-rvn-test__=1. For example, if production traffic uses https://app.example.com/health, validate the standby service with:
?preview=green.
To use an HTTP header instead of a query parameter:
X-Ravion-Test: 1. A service can use either the query-string selector or the header selector, not both at once.
Sticky sessions and traffic shifts
Sticky sessions is on by default. Ravion then turns on target-group stickiness for the service’s production and alternate target groups, so the load balancer keeps repeat requests on the same task when possible. With the default Load balancer cookie stickiness type, the target-level cookie isAWSALB; AWS may also set AWSALBCORS for CORS support. With Application cookie stickiness, the target-level cookie is the configured Application cookie name, and AWS may also set AWSALBAPP-* cookies. Stickiness cookie duration sets how long these target-level cookies last.
When target groups are sticky, AWS also requires ALB group stickiness on the listener rules that forward to them, so Ravion turns it on for the production and test listener rules. Group stickiness uses the AWSALBTG cookie (and AWSALBTGCORS for CORS requests) to keep a client on the target group it reached last. AWS manages that cookie name; Application cookie name applies only to target-level stickiness.
Blue/green, Linear, and Canary deployments move traffic by changing the listener rule’s target-group weights. The weights apply only to requests without an AWSALBTG cookie. A client with the cookie keeps going to the target group the cookie names, and AWS counts the duration from the client’s last request, so a client that sends requests more often than the duration (for example, an app polling every 30 seconds) never leaves the old target group. Once the bake time ends, ECS removes the old tasks, and the load balancer answers those clients with 503 errors until the cookie expires.
That is why Deployment stickiness duration defaults to 1 second, the shortest duration AWS allows. It meets the AWS requirement without pinning clients across a deploy: repeat requests still reach the same task through target-level stickiness, but any request more than a second after the previous one enters the current traffic split. A higher value keeps clients on the deployment they first reached during the traffic shift, at the cost of 503s for any of them still active when the old tasks are removed. The value can’t exceed the bake time, and AWS recommends 5 minutes or less. See Blue/green deployments with Application Load Balancer.
Ravion applies Deployment stickiness duration to the production and test listener rules before each deploy, so changing it, or turning Sticky sessions off, updates existing rules on the next deploy. With Sticky sessions off, Ravion turns group stickiness off on the rules.
To clear stickiness for a browser, open the browser developer tools, go to Application or Storage > Cookies for the service domain, and delete the relevant cookies: AWSALBTG and AWSALBTGCORS for ALB group stickiness; AWSALB and AWSALBCORS for the default target-level stickiness; and the configured Application cookie name plus any AWSALBAPP-* cookies when Application cookie stickiness is selected. For API clients, remove those cookie names from the cookie jar or stop sending them in the Cookie header. The next request then enters the current traffic split like a new client.
Builder settings
Builder settings apply to Railpack and Dockerfile builds.
Start with the default builder size, then adjust based on build duration and resource usage.
Compliance
The Compliance section holds log retention and CloudWatch alarms. Log retention (days) defaults to the value configured on the ECS cluster’s Compliance section, so one cluster setting keeps every service consistent. Set a value here to override it for this service. Use 0 to retain logs indefinitely. CloudWatch alarms are enabled by default for average CPU utilization, average memory utilization, and running task count. Because the service owns its target group, it also alarms on unhealthy targets, target 5xx responses, and target response time for this service only. Load balancer level alarms live on the ECS cluster. The running task alarm uses the Container InsightsRunningTaskCount metric and stays silent when Container Insights is disabled on the cluster. Every alarm treats missing data as not breaching and must breach for the configured number of consecutive periods before it fires. Add SNS topic ARNs as Alarm actions and OK actions to be notified.
Configuration
*Conditionally required based on the selected build source or capacity provider.
Design decisions
- The module always models an HTTP web service behind an Application Load Balancer. NLB, worker, and service discovery patterns are intentionally outside this module definition.
- Tasks default to private subnets even for public web services. The ALB is public; the tasks remain private when the VPC has NAT or equivalent egress.
- Built images are pushed to an ECR repository created with the service stack. Managed ECR repository lets a pipeline push images to that repository without a module build config. Pull from image registry lets teams bring their own image pipeline.
- The service uses the autoscaling minimum when autoscaling is enabled and the Desired tasks input when autoscaling is disabled.
- Advanced Terraform variables exist for exceptional lower-level overrides. Prefer the typed Ravion fields whenever possible.
Learn more
- Amazon ECS services
- Application Load Balancer listener rules
- Amazon ECS capacity providers
- Amazon ECS service auto scaling
- Railpack documentation
Inputs reference
All inputs forrvn-ecs-web version 2.10.0. Use the name shown for each field as the input key in module config.
- Inputs: ECS cluster to environment variables — ECS cluster, Web service, Domains, Build config, Dockerfile, Railpack, Deployment, Health check, HTTP listener rules, Container resources, Autoscaling, Environment variables
- Inputs: Pre and post deploy to terraform settings — Pre and post deploy, Logging, IAM roles and policies, Networking and deployment, Persistent storage, Compliance, Builder config, Image registry lifecycle, Misc, Terraform settings