From 2b422fbe9b8cdb1b9d723a3960f76aed93be2acf Mon Sep 17 00:00:00 2001 From: akash1810 Date: Tue, 13 Oct 2026 07:26:53 +0100 Subject: [PATCH] fix(cdk): Fail with invalid weighting configuration Validate the weighting configuration: if a target is set to receive traffic, ensure it has some compute. This is after https://github.com/guardian/dotcom-rendering/pull/16922 and https://github.com/guardian/dotcom-rendering/pull/16757 accidentally edited the wrong "minimum" value. --- dotcom-rendering/cdk/lib/renderingStack.ts | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dotcom-rendering/cdk/lib/renderingStack.ts b/dotcom-rendering/cdk/lib/renderingStack.ts index fb23103832a..d48d5602b83 100644 --- a/dotcom-rendering/cdk/lib/renderingStack.ts +++ b/dotcom-rendering/cdk/lib/renderingStack.ts @@ -216,6 +216,29 @@ export class RenderingCDKStack extends CDKStack { const { guApp, stage, instanceType, scaling, domainName, ecsProps } = props; + // If a target is set to receive traffic, ensure it has some compute. + // TODO remove once GuCDK does this. + const maybeTargetGroupWeights = ecsProps?.targetGroupWeights; + if (maybeTargetGroupWeights) { + const { ec2: ec2Weight, ecs: ecsWeight } = maybeTargetGroupWeights; + const totalWeight = ec2Weight + ecsWeight; + + const ec2Min = scaling.minimumInstances; + const ecsMin = ecsProps.scaling.minimumTasks; + + if (ec2Weight > 0 && ec2Min <= 0) { + throw new Error( + `Invalid configuration: EC2 is set to serve traffic (${ec2Weight} of ${totalWeight} requests), but has ${ec2Min} instances.`, + ); + } + + if (ecsWeight > 0 && ecsMin <= 0) { + throw new Error( + `Invalid configuration: ECS is set to serve traffic (${ecsWeight} of ${totalWeight} requests), but has ${ecsMin} tasks.`, + ); + } + } + super(scope, id, { // Any version of this app should run in the eu-west-1 region env: { region: 'eu-west-1' },