import * as ec2 from "aws-cdk-lib/aws-ec2"; import * as ecs from "aws-cdk-lib/aws-ecs"; import * as elbv2 from "aws-cdk-lib/aws-elasticloadbalancingv2"; import { Construct } from "constructs"; import type { ServiceImage } from "./docker-image.js"; import type { Cacheable } from "./domain.js"; export type ServiceInstance = (typeof SERVICE_INSTANCES)[keyof typeof SERVICE_INSTANCES]; export declare const SERVICE_INSTANCES: { readonly MICRO: { readonly cpu: 256; readonly memoryLimitMiB: 512; }; }; /** * A containerized service on ECS Fargate. With `loadBalancer` it sits behind an *internal* * Application Load Balancer, ready to be fronted by a `Domain`'s CloudFront VPC origin; without * one it is reachable only from inside the VPC, typically by Cloud Map DNS from another service. * * Ingress is closed by default: wire it explicitly, e.g. * `api.connections.allowFrom(web, ec2.Port.tcp(3000))`. */ export declare class Service extends Construct implements Cacheable, ec2.IConnectable { readonly service: ecs.FargateService; readonly containerName: string; readonly cacheKey: string; /** Only set when `loadBalancer` was requested. */ readonly loadBalancer?: elbv2.ApplicationLoadBalancer; constructor(scope: Construct, id: string, props: ServiceProps); get connections(): ec2.Connections; } export type LoadBalancerOptions = { /** Target group health check path. Defaults to '/'. */ healthCheckPath?: string; /** Scale out to at most this many tasks on request count. Omit for a fixed single task. */ maxCapacity?: number; /** Requests per task before scaling out. Defaults to 50. */ requestsPerTarget?: number; }; export type ServiceProps = { /** Cluster to run on. Several services can share one. */ cluster: ecs.ICluster; image: ServiceImage; containerPort: number; /** Network bucket for the tasks and internal ALB. Defaults to private-with-egress. */ subnetType?: ec2.SubnetType.PRIVATE_WITH_EGRESS | ec2.SubnetType.PRIVATE_ISOLATED; /** Container name, also the log stream prefix. Defaults to 'app'. */ containerName?: string; /** Defaults to `SERVICE_INSTANCES.MICRO`. */ instance?: ServiceInstance; /** Runtime environment, merged over the image's build-time variables. */ environment?: Record; /** Runtime secrets, merged over the image's. */ secrets?: Record; /** Container-level health check. An ALB-fronted service is already probed via its target group. */ healthCheck?: ecs.HealthCheck; /** Front the service with an internal ALB. Omit for a service reached only from inside the VPC. */ loadBalancer?: LoadBalancerOptions; /** * Register under this name in the cluster's default Cloud Map namespace, so other services * reach it privately at `.:`. The cluster must already have a * namespace (`cluster.addDefaultCloudMapNamespace({ name })`). */ discoveryName?: string; };