Skip to content

Commit

Permalink
fix(toolkit): improve error message for large templates (#900)
Browse files Browse the repository at this point in the history
Fixes #34
  • Loading branch information
Elad Ben-Israel committed Oct 11, 2018
1 parent 929a2c1 commit 0ed10b5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface DeployStackResult {
readonly stackArn: string;
}

const LARGE_TEMPLATE_SIZE_KB = 50;

export async function deployStack(stack: cxapi.SynthesizedStack,
sdk: SDK,
toolkitInfo?: ToolkitInfo,
Expand Down Expand Up @@ -104,11 +106,14 @@ async function makeBodyParameter(stack: cxapi.SynthesizedStack, toolkitInfo?: To
const templateURL = `${toolkitInfo.bucketUrl}/${key}`;
debug('Stored template in S3 at:', templateURL);
return { TemplateURL: templateURL };
} else if (templateJson.length > 51_200) {
error('The template for stack %s is %d bytes long, a CDK Toolkit stack is required for deployment of templates larger than 51,200 bytes. ' +
'A CDK Toolkit stack can be created using %s',
stack.name, templateJson.length, colors.blue(`cdk bootstrap '${stack.environment!.name}'`));
throw new Error(`The template for stack ${stack.name} is larger than 50,200 bytes, and no CDK Toolkit info was provided`);
} else if (templateJson.length > LARGE_TEMPLATE_SIZE_KB * 1024) {
error(
`The template for stack "${stack.name}" is ${Math.round(templateJson.length / 1024)}KiB. ` +
`Templates larger than ${LARGE_TEMPLATE_SIZE_KB}KiB must be uploaded to S3.\n` +
'Run the following command in order to setup an S3 bucket in this environment, and then re-deploy:\n\n',
colors.blue(`\t$ cdk bootstrap ${stack.environment!.name}\n`));

throw new Error(`Template too large to deploy ("cdk bootstrap" is required)`);
} else {
return { TemplateBody: templateJson };
}
Expand Down

0 comments on commit 0ed10b5

Please sign in to comment.