Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toolkit): improve error message for large templates #900

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Changes from 1 commit
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
16 changes: 11 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,15 @@ 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(` $ cdk bootstrap ${stack.environment!.name}\n`));
eladb marked this conversation as resolved.
Show resolved Hide resolved

throw new Error(`Template for stack "${stack.name}" > ${LARGE_TEMPLATE_SIZE_KB}KiB`);
eladb marked this conversation as resolved.
Show resolved Hide resolved
} else {
return { TemplateBody: templateJson };
}
Expand Down