import * as cdk from 'aws-cdk-lib'; 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 * as constructs from 'constructs'; /** * Fargate Task Definition Properties. */ export interface RioFargateServiceProps { /** * The stage of the service, e.g. 'prod'. */ readonly stage: string; /** * The Name of the service. */ readonly serviceName: string; /** * The version of the service, e.g. the git hash of the corresponding commit. */ readonly version: string; /** * The frameworks in uses. * * @defaultValue - No frameworks. */ readonly frameworks?: Framework[]; /** * The VPC of the service's ecs.Cluster if no cluster is explicitly passed as prop. */ readonly vpc: ec2.IVpc; /** * The Fargate cluster to run the service in. * If not null, the cluster.vpc MUST match the vpc provided as direct argument. * * @defaultValue - Create a new Fargate cluster with default properties */ readonly cluster?: ecs.ICluster; /** * Container definition options like image, cpu, memory. */ readonly containerDefinitionOption: ContainerDefinitionOptions; /** * Fargate Task Definition Properties. */ readonly fargateOptions: FargateTaskDefinitionProps; /** * Loadbalancer options. */ readonly loadBalancerOptions?: LoadBalancerOptions; /** * Datadog integration properties */ readonly datadogOptions?: DatadogIntegrationProps; } export declare enum Framework { /** * Spring Framework, Spring Boot, and Spring Cloud AWS. */ SPRING = 0 } export interface ContainerDefinitionOptions { /** * The image used to start a container. * * This string is passed directly to the Docker daemon. * Images in the Docker Hub registry are available by default. * Other repositories are specified with either repository-url/image:tag or repository-url/image\@digest. */ readonly image: ecs.ContainerImage; /** * The environment variables to pass to the container. * * Some Datadog specific environment variables are not allowed to be set, * because they are set automatically or computed from other attributes. * These are: * * DD_ENV: Set same as prop stage * * DD_SERVICE: Set same as prop serviceName * * DD_VERSION: Set same as prop version * * DD_TAGS: Set same as DatadogIntegrationProps#additionalTags * * DD_LOGS_INJECTION: true * Other DD_-prefixed vaiable may be added to this list. * * Other Environment variables set by default are overwritten if passed. * These are: * * DD_SERVICE_MAPPING: database:fargate-web-app-aurora,java-aws-sdk:fargate-web-app-aws-sdk,kafka:fargate-web-app-kafka,mysql:fargate-web-app-aurora * * DD_TRACE_SAMPLE_RATE: 1.0 * * @defaultValue - No environment variables. */ readonly environment?: { [key: string]: string; }; /** * The secret environment variables to pass to the container. * * @defaultValue - No secret environment variables. */ readonly secrets?: { [key: string]: ecs.Secret; }; /** * The health check command and associated configuration parameters for the container. * * @defaultValue - Health check configuration from container. */ readonly healthCheck?: ecs.HealthCheck; } export interface FargateTaskDefinitionProps { /** * The number of cpu units used by the task. For tasks using the Fargate launch type, * this field is required and you must use one of the following values, * which determines your range of valid values for the memory parameter: * * 256 (.25 vCPU) - Available memory values: 512 (0.5 GB), 1024 (1 GB), 2048 (2 GB) * * 512 (.5 vCPU) - Available memory values: 1024 (1 GB), 2048 (2 GB), 3072 (3 GB), 4096 (4 GB) * * 1024 (1 vCPU) - Available memory values: 2048 (2 GB), 3072 (3 GB), 4096 (4 GB), 5120 (5 GB), 6144 (6 GB), 7168 (7 GB), 8192 (8 GB) * * 2048 (2 vCPU) - Available memory values: Between 4096 (4 GB) and 16384 (16 GB) in increments of 1024 (1 GB) * * 4096 (4 vCPU) - Available memory values: Between 8192 (8 GB) and 30720 (30 GB) in increments of 1024 (1 GB) * * @defaultValue 512 */ readonly cpu: number; /** * The amount (in MiB) of memory used by the task. For tasks using the Fargate launch type, * this field is required and you must use one of the following values, which determines your range of valid values for the cpu parameter: * * 512 (0.5 GB), 1024 (1 GB), 2048 (2 GB) - Available cpu values: 256 (.25 vCPU) * * 1024 (1 GB), 2048 (2 GB), 3072 (3 GB), 4096 (4 GB) - Available cpu values: 512 (.5 vCPU) * * 2048 (2 GB), 3072 (3 GB), 4096 (4 GB), 5120 (5 GB), 6144 (6 GB), 7168 (7 GB), 8192 (8 GB) - Available cpu values: 1024 (1 vCPU) * * Between 4096 (4 GB) and 16384 (16 GB) in increments of 1024 (1 GB) - Available cpu values: 2048 (2 vCPU) * * Between 8192 (8 GB) and 30720 (30 GB) in increments of 1024 (1 GB) - Available cpu values: 4096 (4 vCPU) * * @defaultValue 1024 */ readonly memoryLimitMiB: number; /** * Desired count of running tasks * * @defaultValue - When creating the service, default is 1; when updating the service, default uses * the current task number. */ readonly desiredCount?: number; /** * The operating system that your task definitions are running on. * * @defaultValue - Using ecs.OperatingSystemFamily.LINUX and ecs.CpuArchitecture.X86_64 */ readonly runtimePlatform?: ecs.RuntimePlatform; } export interface ListenerRule { readonly priority: number; readonly conditions: elbv2.ListenerCondition[]; } export interface LoadBalancerOptions { /** * Listener for an Application Load Balancer */ readonly listener: elbv2.IApplicationListener; /** * One or more path patterns to compare against the request URL. * The maximum size of each string is 128 characters. * The comparison is case sensitive. * The following wildcard characters are supported: * (matches 0 or more characters) and ? (matches exactly 1 character). * * Update requires: No interruption */ readonly listenerRules: ListenerRule[]; /** * Health check options. */ readonly healthCheck: elbv2.HealthCheck; /** * Health check grace period. */ readonly healthCheckGracePeriod: cdk.Duration; /** * The time period during which the load balancer sends a newly registered target a linearly increasing share of the traffic to the target group. *The range is 30-900 seconds (15 minutes). * @defaultValue undefined */ readonly slowStart?: cdk.Duration; /** * The amount of time for Elastic Load Balancing to wait before deregistering a target. * The range is 0-3600 seconds. * @defaultValue 5 */ readonly deregistrationDelay?: cdk.Duration; } export interface DatadogIntegrationProps { /** * The minimum number of CPU units to reserve for the container. * * @defaultValue - 64 */ readonly cpu?: number; /** * The amount (in MiB) of memory to present to the container. * * If your container attempts to exceed the allocated memory, the container * is terminated. * * At least one of memoryLimitMiB and memoryReservationMiB is required for non-Fargate services. * * @defaultValue - 128 */ readonly memoryLimitMiB?: number; /** * The amount of virtual CPU units to be reserved for the firelens log-router container (i.e. aws-for-fluent-bit). * * This only applies for the AWS_FIRE_LENS logging mode. * Setting it for any other logging mode will cause an exception. * * @defaultValue - 64 */ readonly awsFireLensCpu?: number; /** * The amount of memory (in MiB) reserved for the firelens log-router container (i.e. aws-for-fluent-bit). * * This only applies for the AWS_FIRE_LENS logging mode. * Setting it for any other logging mode will cause an exception. * * @defaultValue - 64 */ readonly awsFireLensMemoryLimitMiB?: number; /** * The logging mode for the service. * * @defaultValue - Using the Datadog log forwarder lambda provided by the datadog-integration. */ readonly loggingModeForService?: DataDogLoggingMode; /** * The logging mode for the Datadog agent sidecar. * * @defaultValue - No logs in Datadog, Cloudwatch only. */ readonly loggingModeForDatadogAgent?: DataDogLoggingMode; /** * GET endpoints to ignore in Datadog's APM overview. This is useful to filter out all health check calls. * @defaultValue - No endpoints are ignored. */ readonly apmGetEndpointsToIgnore?: string[]; /** * Configure if the Datadog agent sidecar is marked as essential. * * @defaultValue - true. */ readonly datadogSidecarEssential?: boolean; /** * Configures the docker image tag for datadog sidecar * @defaultValue - 'latest' */ readonly datadogSidecarTag?: string; /** * When you set up a restart policy for a container, Amazon ECS can restart the container without needing to replace the task * @defaultValue - true */ readonly enableRestartPolicy?: boolean; /** * The exit codes to be ignored by the restart policy * @defaultValue - [0] */ readonly restartIgnoredExitCodes?: number[]; /** * Configure additional tags, which are appended to the defaults, * When you define custom tags we would be glad if you contact us. * We would like to learn about your use cases. * * Default tags are not allowed to be overridden! * * Defaults are: * * env: Set to RioFargateServiceProps#stage prop * * service: Set to RioFargateServiceProps#serviceName prop * * version: Set to RioFargateServiceProps#version prop * * account_id:$\{accountID\} * * account_name:$\{accountName\} * * region:$\{AWSRegion\} * * team:$\{teamName from ssm param /config/team/name\} * * team_identifier:$\{teamIdentifier from ssm param /config/team/identifier\} */ readonly additionalTags?: { [key: string]: string; }; } export declare enum DataDogLoggingMode { /** * Forward logs directly to Datadog using AWS FireLens as log router, * see https://docs.datadoghq.com/integrations/ecs_fargate/?tab=fluentbitandfirelens#log-collection. */ AWS_FIRE_LENS = 0, /** * Store logs in AWS Cloudwatch and use the RIO customized Datadog log forwarder lambda from the legacy * datadog-integration, to forward the logs to Datadog, * * @see https://bitbucket.collaboration-man.com/projects/RIODEV/repos/datadog-integration/browse * @deprecated use DATADOG_FORWARDER_LAMBDA */ FORWARDER_LAMBDA = 1, /** * Store logs in AWS Cloudwatch and use the Datadog log forwarder lambda to forward the logs to Datadog, * see https://docs.datadoghq.com/integrations/ecs_fargate/?tab=logdriver#log-collection. */ DATADOG_FORWARDER_LAMBDA = 2, /** * Only log to AWS Cloudwatch without forwarding the logs to Datadog. */ NONE = 3 } export declare class RioFargateService extends constructs.Construct implements ec2.IConnectable { private static readonly DD_ENV_DENY_LIST; private static readonly DD_TAG_DENY_LIST; private readonly DEFAULT_APM_GET_ENDPOINTS_TO_IGNORE; private readonly DEFAULT_DATADOG_SIDECAR_CPU; private readonly DEFAULT_DATADOG_SIDECAR_MEMORY_LIMIT_MIB; private readonly DEFAULT_DATADOG_SIDECAR_ESSENTIAL; private readonly DEFAULT_DATADOG_ENABLE_RESTART_POLICY; private readonly DEFAULT_DATADOG_RESTART_IGNORED_EXIT_CODES; private readonly DEFAULT_LOGGING_MODE_FOR_SERVICE; private readonly DEFAULT_LOGGING_MODE_FOR_DATADOG_SIDECAR; private readonly DEFAULT_DEREGISTRATION_DELAY; private readonly DEFAULT_SLOW_START; private readonly DEFAULT_DATADOG_SIDECAR_TAG; private readonly DEFAULT_LOG_ROUTER_CPU; private readonly DEFAULT_LOG_ROUTER_MEMORY_LIMIT_MIB; private readonly FIRELENS_CONFIG_BUCKET_ARN; private readonly FIRELENS_CONFIG_FILE_PATH; readonly serviceContainerDefinition: ecs.ContainerDefinition; readonly datadogSideCarContainerDefinition: ecs.ContainerDefinition; readonly logRouterContainerDefinition?: ecs.ContainerDefinition; readonly taskDefinition: ecs.FargateTaskDefinition; readonly connections: ec2.Connections; readonly service: ecs.FargateService; readonly targetGroup: elbv2.ApplicationTargetGroup | undefined; constructor(scope: constructs.Construct, id: string, props: RioFargateServiceProps); }