Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions dotcom-rendering/cdk/lib/renderingStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' },
Expand Down
Loading