From 78265a43fad8cf7f8cef53b69ec3a0e3156da4eb Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Thu, 11 Oct 2018 14:25:15 +0300 Subject: [PATCH 1/2] fix(toolkit): improve error message for large templates Fixes #34 --- packages/aws-cdk/lib/api/deploy-stack.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index 3d2ec112f0341..9d5c731107f0c 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -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, @@ -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`)); + + throw new Error(`Template for stack "${stack.name}" > ${LARGE_TEMPLATE_SIZE_KB}KiB`); } else { return { TemplateBody: templateJson }; } From c9bf2d8585c5a0639cc66f4df2ef6e1f62b0ba2f Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Thu, 11 Oct 2018 15:12:33 +0300 Subject: [PATCH 2/2] cr fixes --- packages/aws-cdk/lib/api/deploy-stack.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index 9d5c731107f0c..6d3a5c71e79e9 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -107,14 +107,13 @@ async function makeBodyParameter(stack: cxapi.SynthesizedStack, toolkitInfo?: To debug('Stored template in S3 at:', templateURL); return { TemplateURL: templateURL }; } 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`)); + colors.blue(`\t$ cdk bootstrap ${stack.environment!.name}\n`)); - throw new Error(`Template for stack "${stack.name}" > ${LARGE_TEMPLATE_SIZE_KB}KiB`); + throw new Error(`Template too large to deploy ("cdk bootstrap" is required)`); } else { return { TemplateBody: templateJson }; }