Service
Source:
src/AWS/ECS/Service.ts
An ECS service for running long-lived tasks.
Service keeps a registered task definition running with awsvpc networking.
Load balancing is explicit: pass user-supplied loadBalancers target
groups, or set public: true to have Alchemy provision a public ALB +
listener + target group as a convenience. Launch behavior is controlled via
launchType (default FARGATE) or a capacityProviderStrategy.
Most configuration is updated in place via updateService
(desiredCount, task definition, network, deployment config, placement,
exec, load balancers, tags). Only truly-immutable aspects — serviceName,
cluster, launchType↔capacityProviderStrategy switch, deploymentController
type, schedulingStrategy, enableECSManagedTags, role — replace the
service.
Creating Services
Section titled “Creating Services”Internal Service
const service = yield* Service("WorkerService", { cluster, task: workerTask, vpcId: vpc.vpcId, subnets: [privateSubnet1.subnetId, privateSubnet2.subnetId], securityGroups: [workerSecurityGroup.groupId], desiredCount: 2,});Public HTTP Service (Alchemy-managed ALB)
const service = yield* Service("ApiService", { cluster, task: apiTask, vpcId: vpc.vpcId, subnets: [publicSubnet1.subnetId, publicSubnet2.subnetId], securityGroups: [serviceSecurityGroup.groupId], public: true,});Load Balancing
Section titled “Load Balancing”const service = yield* Service("ApiService", { cluster, task: apiTask, vpcId: vpc.vpcId, subnets: [subnet1.subnetId, subnet2.subnetId], loadBalancers: [ { targetGroupArn, containerName: apiTask.containerName, containerPort: apiTask.port, }, ],});Capacity & Placement
Section titled “Capacity & Placement”const service = yield* Service("WorkerService", { cluster, task: workerTask, vpcId: vpc.vpcId, subnets: [subnet.subnetId], capacityProviderStrategy: [ { capacityProvider: "FARGATE_SPOT", weight: 4 }, { capacityProvider: "FARGATE", weight: 1, base: 1 }, ], placementStrategy: [{ type: "spread", field: "attribute:ecs.availability-zone" }],});Deployment
Section titled “Deployment”const service = yield* Service("ApiService", { cluster, task: apiTask, vpcId: vpc.vpcId, subnets: [subnet1.subnetId, subnet2.subnetId], desiredCount: 3, enableExecuteCommand: true, deploymentConfiguration: { minimumHealthyPercent: 100, maximumPercent: 200, deploymentCircuitBreaker: { enable: true, rollback: true }, }, healthCheckGracePeriodSeconds: 30,});