UNPKG

@scloud/cdk-patterns

Version:

Serverless CDK patterns for common infrastructure needs

39 lines (38 loc) 2.54 kB
import { DnsValidatedCertificate } from 'aws-cdk-lib/aws-certificatemanager'; import { Vpc } from 'aws-cdk-lib/aws-ec2'; import { ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns'; import { Repository } from 'aws-cdk-lib/aws-ecr'; import { IHostedZone } from 'aws-cdk-lib/aws-route53'; import { Construct } from 'constructs'; /** * Builds an ApplicationLoadBalancedFargateService that runs a container on ECS Fargate. * * Warning! This pattern is not 'pure' serverless! It gennerates 24x7 running costs per container (rather than being billed on traffic/storage). * * Warning! If you don't pass a vpc, this construct creates a vpc for you and limits the nuber of NAT gateways to 1 to reduce cost. This is less resilient, but NAT gateways are costly! * * If you'd like to avoid this tradeoof, pass in a vpc you've createed that ha zero NAT gateways and is configured with PrivateEndpoint(s) that will allow ECS to pull container images. * * @param serviceName Name for the service * @param zone DNS zone * @param domain Optional: by default the zone name will be used as the DNS name for the service (e.g. 'example.com') but you can specify a different domain here (e.g. 'subdomain.example.com'). * @param environment Any environment variables for the container * @param repository Optional: if you want to use an existing container image repository * @param tag Optional: defaults to 'latest' * @param vpc Optional: if you want to use an existing VPC. In not set, a vpc will be created for you * @param cpu Optional: defaults to 512 * @param memory Optional: defaults to 1024 * @param taskCount Optional: defaults to 2 for redundancy. Set to 1 if you want to reduce cost. * @param zeroTasks Sets task count to zero. Pass true if you don't have an image in ECR yet, otherwise this construct will fail to build. * @param containerPort Optional: defaults to 3000. This is the port the application in your container listens on. * @returns Deplyment detais */ export declare class FargateService extends Construct { certificate: DnsValidatedCertificate; repository: Repository; albFargateService: ApplicationLoadBalancedFargateService; vpc: Vpc; constructor(scope: Construct, id: string, serviceName: string, zone: IHostedZone, domain?: string, environment?: { [key: string]: string; }, repository?: Repository | undefined, tag?: string, vpc?: Vpc | undefined, cpu?: number, memory?: number, taskCount?: number, zeroTasks?: boolean, containerPort?: number); }