Skip to main content

AwsEcsAlbServiceModule

AwsEcsAlbServiceModule creates an Application Load Balancer in front of ECS executions, with its listeners, routing rules and targets.

@cost

An ALB bills every hour it exists, about $0.0225 an hour in us-east-1 (about $16 a month) whether it serves or not, plus about $0.008 per load balancer capacity unit-hour of traffic. Data sent to the internet is billed on top.

@downtime

Changing a target group's health check updates it in place. A replaced load balancer gets a new DNS name, so whatever calls it by the old one fails until it moves. A replaced target group drains its targets for up to 300 seconds, AWS's default deregistration delay.

@example

TypeScript

import { type Execution, type Region, type Subnet, stub } from '@quadnix/octo';
import { AwsEcsAlbServiceModule } from '@quadnix/octo-aws-cdk/modules/service/aws-ecs-alb-service';

octo.loadModule(AwsEcsAlbServiceModule, 'my-alb-module', {
albName: 'my-load-balancer',
listeners: [{
DefaultActions: [{
action: {
TargetGroups: [{ targetGroupName: 'my-target-group', Weight: 100 }],
},
actionType: 'forward',
}],
Port: 80,
rules: [],
}],
region: stub<Region>('${{my-region-module.model.region}}'),
subnets: [
stub<Subnet>('${{my-public-subnet-1-module.model.subnet}}'),
stub<Subnet>('${{my-public-subnet-2-module.model.subnet}}'),
],
targets: [{
containerName: 'web',
containerPort: 3000,
execution: stub<Execution>('${{my-execution-module.model.execution}}'),
healthCheck: {
HealthCheckIntervalSeconds: 30,
HealthCheckPath: '/health',
HealthCheckPort: 3000,
HealthCheckProtocol: 'HTTP',
HealthCheckTimeoutSeconds: 5,
HealthyThresholdCount: 3,
Matcher: { HttpCode: 200 },
UnhealthyThresholdCount: 3,
},
Name: 'my-target-group',
}]
});
@group

Modules/Service/AwsEcsAlbService

@limit

AWS needs an ALB's subnets in at least two availability zones, so its region comes from AwsMultiAzRegionModule.

@limit

albName is at most 32 characters, unique in its region. The load balancer is internet-facing and answers anyone who reaches it, even behind AwsCloudFrontServiceModule.

@limit

Every listener speaks plain HTTP: the load balancer holds no certificate and serves no HTTPS. Users reach it over HTTPS only through AwsCloudFrontServiceModule in front of it.

@limit

Every target group registers tasks by IP and speaks HTTP/1 to them over IPv4; HTTP/2 and gRPC to a task are not available.

@losesData

Nothing: a load balancer holds no data.

@replaces

Changing albName or region replaces the load balancer; its subnets change in place. Changing a target's name, port or protocol replaces its target group.

@see

Hierarchy

Index

Constructors

constructor

  • Parameters

    • moduleId: string

      The ID this module is loaded under.

    Returns AwsEcsAlbServiceModule

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

  • Validates the subnets are public, creates the load balancer, and overlays it onto the executions it routes to.


    Parameters

    Returns Promise<[AwsEcsAlbService, AwsEcsAlbServiceOverlay]>

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

  • registerMetadata(inputs: AwsEcsAlbServiceModuleSchema): Promise<{ awsAccountId: string; awsAvailabilityZones: string[]; awsRegionId: string; subnets: Subnet[] }>
  • Resolves the account, region, availability zones, and the subnet models this load balancer sits in.


    Parameters

    Returns Promise<{ awsAccountId: string; awsAvailabilityZones: string[]; awsRegionId: string; subnets: Subnet[] }>