Fix ALB listener default action, auto-import numberOfAzs, and correct docs
- Fix HTTP listener in spicy-alb.ts missing default action when no certificate is provided, which would cause CDK synth to fail - Auto-import numberOfAzs from VPC stack exports (NumberOfAZs) in cluster, service, and ALB stacks when not provided via context - Fix CDK_SYNTH_EXAMPLES.md ALB examples using raw vpcId/subnetIds that don't match the actual fromContext() implementation (requires clusterName) - Fix docs overstating "only clusterName required" to list actual required params - Remove package-lock.json and add to .gitignore (project uses pnpm) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -129,10 +129,18 @@ export class SpicyAlbStack extends cdk.Stack {
|
||||
|
||||
// Import all VPC details from VPC stack exports
|
||||
const vpcCidrBlock = cdk.Fn.importValue(`${vpcStackName}-VPCCIDR`).toString();
|
||||
|
||||
// numberOfAzs: use context value if provided, otherwise auto-import from VPC stack export
|
||||
const numberOfAzsRaw = app.node.tryGetContext('numberOfAzs');
|
||||
const numberOfAzs = numberOfAzsRaw ? parseInt(numberOfAzsRaw, 10) : NaN;
|
||||
let numberOfAzs: number;
|
||||
if (numberOfAzsRaw) {
|
||||
numberOfAzs = parseInt(numberOfAzsRaw, 10);
|
||||
} else {
|
||||
const imported = cdk.Fn.importValue(`${vpcStackName}-NumberOfAZs`).toString();
|
||||
numberOfAzs = parseInt(imported, 10);
|
||||
}
|
||||
if (!numberOfAzs || Number.isNaN(numberOfAzs)) {
|
||||
throw new Error('numberOfAzs is required in context (2-4) to import VPC subnets for ALB.');
|
||||
throw new Error('numberOfAzs is required (2-4). Provide via context or ensure VPC stack exports NumberOfAZs.');
|
||||
}
|
||||
const azs = ['A', 'B', 'C', 'D'].slice(0, Math.min(Math.max(numberOfAzs, 1), 4));
|
||||
|
||||
|
||||
@@ -243,10 +243,18 @@ export class SpicyEcsClusterStack extends cdk.Stack {
|
||||
'vpcStackName is required. Provide vpcStackName to import all VPC details from VPC stack exports.'
|
||||
);
|
||||
}
|
||||
// numberOfAzs: use context value if provided, otherwise auto-import from VPC stack export
|
||||
const numberOfAzsRaw = app.node.tryGetContext('numberOfAzs');
|
||||
const numberOfAzs = numberOfAzsRaw ? parseInt(numberOfAzsRaw, 10) : NaN;
|
||||
let numberOfAzs: number;
|
||||
if (numberOfAzsRaw) {
|
||||
numberOfAzs = parseInt(numberOfAzsRaw, 10);
|
||||
} else {
|
||||
// Auto-import from VPC stack export
|
||||
const imported = cdk.Fn.importValue(`${vpcStackName}-NumberOfAZs`).toString();
|
||||
numberOfAzs = parseInt(imported, 10);
|
||||
}
|
||||
if (!numberOfAzs || Number.isNaN(numberOfAzs)) {
|
||||
throw new Error('numberOfAzs is required in context (2-4) to import subnets from the VPC stack.');
|
||||
throw new Error('numberOfAzs is required (2-4). Provide via context or ensure VPC stack exports NumberOfAZs.');
|
||||
}
|
||||
|
||||
// Tags
|
||||
|
||||
@@ -187,10 +187,18 @@ export class SpicyEcsServiceStack extends cdk.Stack {
|
||||
|
||||
// Import all VPC details from VPC stack exports
|
||||
const vpcCidrBlock = cdk.Fn.importValue(`${vpcStackName}-VPCCIDR`).toString();
|
||||
|
||||
// numberOfAzs: use context value if provided, otherwise auto-import from VPC stack export
|
||||
const numberOfAzsRaw = app.node.tryGetContext('numberOfAzs');
|
||||
const numberOfAzs = numberOfAzsRaw ? parseInt(numberOfAzsRaw, 10) : NaN;
|
||||
let numberOfAzs: number;
|
||||
if (numberOfAzsRaw) {
|
||||
numberOfAzs = parseInt(numberOfAzsRaw, 10);
|
||||
} else {
|
||||
const imported = cdk.Fn.importValue(`${vpcStackName}-NumberOfAZs`).toString();
|
||||
numberOfAzs = parseInt(imported, 10);
|
||||
}
|
||||
if (!numberOfAzs || Number.isNaN(numberOfAzs)) {
|
||||
throw new Error('numberOfAzs is required in context (2-4) to import VPC subnets.');
|
||||
throw new Error('numberOfAzs is required (2-4). Provide via context or ensure VPC stack exports NumberOfAZs.');
|
||||
}
|
||||
const azs = ['A', 'B', 'C', 'D'].slice(0, Math.min(Math.max(numberOfAzs, 1), 4));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user