Skip to main content

AwsEcsExecutionModule

AwsEcsExecutionModule runs a server's deployments as a long-running ECS Fargate service in a subnet, with desiredCount tasks, environmentVariables, securityGroupRules and filesystems mounted.

@cost

Fargate bills each task's vCPU and memory every second it runs, about $0.0405 per vCPU-hour and $0.0044 per GB-hour on x86_64 in us-east-1, about a fifth less on arm64. A task of 0.25 vCPU and 0.5 GB runs about $9 a month, multiplied by desiredCount, and costs the same idle as busy. Its logs bill about $0.50 per GB written to CloudWatch.

@downtime

A new deployment rolls: ECS starts the new tasks, waits for them to pass the load balancer's health check, then drains the old ones for up to 300 seconds, so a release takes several minutes and serves throughout. Changing desiredCount or the load balancers updates the service in place.

@example

TypeScript

import { type Deployment, type Environment, type Filesystem, type Subnet, stub } from '@quadnix/octo';
import { AwsEcsExecutionModule } from '@quadnix/octo-aws-cdk/modules/execution/aws-ecs-execution';

octo.loadModule(AwsEcsExecutionModule, 'my-execution-module', {
deployments: {
main: {
containerProperties: {
cpu: 512,
image: {
essential: true,
name: 'main-app',
ports: [{ containerPort: 3000, protocol: 'tcp' }]
},
memory: 1024,
},
deployment: stub<Deployment>('${{my-deployment-module.model.deployment}}'),
},
sidecars: []
},
desiredCount: 2,
environment: stub<Environment>('${{my-environment-module.model.environment}}'),
environmentVariables: {
LOG_LEVEL: 'info'
},
executionId: 'my-app-execution',
filesystems: [stub<Filesystem>('${{my-filesystem-module.model.filesystem}}')],
securityGroupRules: [{
CidrBlock: '0.0.0.0/0',
Egress: false,
FromPort: 3000,
IpProtocol: 'tcp',
ToPort: 3000,
}],
subnet: stub<Subnet>('${{my-subnet-module.model.subnet}}'),
});
@group

Modules/Execution/AwsEcsExecution

@limit

The service runs in one subnet, so in one availability zone. A task's CPU is one of 256 to 16384 units, and its memory must be a size Fargate pairs with that CPU.

@limit

Tasks run all the time, so a service with desiredCount 0 serves nothing and one with 1 has nothing to fail over to.

@limit

The service runs desiredCount tasks and never scales with load: more or fewer tasks is a change of desiredCount in a run. Tasks run on Fargate only, never on Fargate Spot or on EC2 instances of your own.

@limit

One IAM role both lets ECS pull the image and write logs, and is the role the containers run as, so the code holds every grant of its servers together with AmazonECSTaskExecutionRolePolicy.

@limit

Containers log to one CloudWatch log group per execution, through the awslogs driver; no other log destination can be set.

@limit

The log group /ecs/<executionId> must not exist before the first apply, which fails otherwise.

@limit

Each filesystem is mounted read-write at /mnt/<filesystemName> in every container of the task, over the filesystem's root.

@limit

The service has no deployment circuit breaker: a release whose tasks never become healthy is not rolled back.

@losesData

Whatever a task writes to its own disk is lost when the task stops; data meant to outlive it goes into an EFS filesystem (filesystems) or a storage service. Its logs are kept for logRetentionInDays and deleted with it.

@replaces

Changing executionId or the environment replaces the service. A change to an image, its CPU, memory or environment variables registers a new task definition and rolls the service onto it.

@see

Hierarchy

Index

Constructors

constructor

  • Parameters

    • moduleId: string

      The ID this module is loaded under.

    Returns AwsEcsExecutionModule

Properties

readonlyinheritedmoduleId

moduleId: string

The ID this module was loaded under. It scopes everything the module produces, so the same module class can be loaded more than once.

staticreadonlyinheritedMODULE_PACKAGE

MODULE_PACKAGE: string

The package the module is registered under, set by Module.

staticreadonlyinheritedMODULE_SCHEMA

MODULE_SCHEMA: any

The schema of the module's inputs, set by Module.

Methods

onInit

  • onInit(inputs: AwsEcsExecutionModuleSchema): Promise<(AwsEcsExecution | AwsEcsExecutionOverlay | AwsEcsExecutionServerSecurityGroupOverlay)[]>
  • Creates the execution, resolves the anchors of its server, deployment, subnet, and any sidecars, and opens the security-group rules between them.


    Parameters

    Returns Promise<(AwsEcsExecution | AwsEcsExecutionOverlay | AwsEcsExecutionServerSecurityGroupOverlay)[]>

inheritedregisterHooks

  • registerHooks(): { postCommitHooks?: PostHookSignature[]; postModelActionHooks?: PostHookSignature[]; postResourceActionHooks?: PostHookSignature[]; preCommitHooks?: PreHookSignature[]; preModelActionHooks?: PreHookSignature[]; preResourceActionHooks?: PreHookSignature[] }
  • To hook custom behavior into Octo's lifecycle for the duration of this module. Override it to return the callbacks you want run.

    @see

    Techniques for Hooks.


    Returns { postCommitHooks?: PostHookSignature[]; postModelActionHooks?: PostHookSignature[]; postResourceActionHooks?: PostHookSignature[]; preCommitHooks?: PreHookSignature[]; preModelActionHooks?: PreHookSignature[]; preResourceActionHooks?: PreHookSignature[] }

    • optionalpostCommitHooks?: PostHookSignature[]
    • optionalpostModelActionHooks?: PostHookSignature[]
    • optionalpostResourceActionHooks?: PostHookSignature[]
    • optionalpreCommitHooks?: PreHookSignature[]
    • optionalpreModelActionHooks?: PreHookSignature[]
    • optionalpreResourceActionHooks?: PreHookSignature[]

registerMetadata

  • Resolves the account, region, and the region model this execution is placed in.


    Parameters

    Returns Promise<{ awsAccountId: string; awsRegionId: string; region: Region }>