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

[cli] cdk synth should allow for an option to compact the template file (remove whitespaces) #8712

Closed
2 tasks
mcliff1 opened this issue Jun 24, 2020 · 2 comments
Assignees
Labels
feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. package/tools Related to AWS CDK Tools or CLI

Comments

@mcliff1
Copy link

mcliff1 commented Jun 24, 2020

When producing JSON output cdk synth should have an option to minimize the output template file size.

Use Case

AWS Cloudformation has a limit on the template body size for an template on S3 at 460,800 bytes.

I had attempted to inject this type of filtering after cdk synth in the cdk deploy flow, but quickly got lost.

This will allow deployment of larger stacks.

Proposed solution

Add an option on CDK Synth that will strip out all white spaces from the output template JSON (in my use case this reduced the size from 500k to 250k).

Possibly this could be an option for cdk.json

Other

Using Nested Stacks is the most common way to reduce stack size, in my use case I was doing a lot of with Cross Account CodePipelines which created many permissions objects and was very sensitive to repacking in nested stacks.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@mcliff1 mcliff1 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 24, 2020
@rrrix
Copy link

rrrix commented Jun 24, 2020

In another life in another project, I was using the AWS Amplify CLI, which also outputs everything as very spacey CloudFormation JSON and had hit that same CloudFormation template file size limit.

I ended up added a "hook" (hack?) in the Amplify CLI to use cfn-flip (https://github.com/awslabs/aws-cfn-template-flip) which converts everything to YAML, and has a --clean option (which allows it to fixup Intrinsic Functions to use the shorthand YAML versions).

Perhaps that might be an option worth looking at?

A quick test was able to reduce a random template I have from 64K to 38K (~40% reduction):

$ cfn-flip -y -c pipeline.template.json pipeline.template.yaml
$ ll pipeline.template.*
-rw-r--r--  1 user  staff    64K Jun 23 18:24 pipeline.template.json
-rw-r--r--  1 user  staff    38K Jun 24 12:23 pipeline.template.yaml

@SomayaB SomayaB changed the title CDK synth should allow for an option to compact the template file (remove whitespaces) [cli] cdk synth should allow for an option to compact the template file (remove whitespaces) Jun 25, 2020
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Jun 25, 2020
@mcliff1 mcliff1 closed this as completed Jun 29, 2020
@mcliff1
Copy link
Author

mcliff1 commented Jun 29, 2020

@rrrix re: approach of plugging in a hook into cdk deploy

I spent a fair amount of time trying to do that and quickly discovered that deploy action is pretty complex; I think a great solution to this feature request could be to enable a hook for 'post-processing' with the deploy.

mergify bot pushed a commit that referenced this issue Jun 15, 2023
Fixes #18694, #8712 

This change adds an option to suppress indentation in CloudFormation template files. Suppressing indentation will reduce the file size of templates.

Indentation can be set by enabling for specific Stacks using the new `suppressTemplateIndentation` property in `StackProps`, or globally using the new `@aws-cdk/core:suppressTemplateIndentation` context key.

This PR provides additional template size reduction beyond the indentation change in  #19656.

@rix0rrr @mackalex @PatMyron 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

3 participants