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

(cdk cli): Create Smaller CloudFormation Templates #18694

Closed
2 tasks done
mckalexee opened this issue Jan 27, 2022 · 3 comments · Fixed by #25892
Closed
2 tasks done

(cdk cli): Create Smaller CloudFormation Templates #18694

mckalexee opened this issue Jan 27, 2022 · 3 comments · Fixed by #25892
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI

Comments

@mckalexee
Copy link

mckalexee commented Jan 27, 2022

Description

Allow options when deploying using the cdk cli that would result in physically smaller CloudFormation template.

Currently the template that is generated and deployed is formatted as JSON with whitespace.

From our testing, simply removing the whitespace can result in a template that is roughly 50% of the size.

Outputting the template as YAML also decreases the template size by roughly the same amount.

Use Case

We have a CDK project that has several lambda functions behind an API. We just ran into the limit where a CloudFormation template has to be less than 1MB.

The number of resources we have is relatively low, but due to the auto generated names of resources the template size is quite large.

If we could minify the template before deploying, or if we could have CDK deploy the template as YAML, we would be able to halve the size of the template and deploy twice as many resources.

Proposed Solution

This would be a combination of previously proposed solutions.

#8712
The above issue suggests having an option to compact the whitespace. This seems like a reasonable proposal.

#2965
The above issue mentions including the option of writing YAML to cdk.out. This appears to have been rejected on the premise that the folder is for machines to read, and that the only benefit of YAML is that it's human readable.

This ignores the fact that the YAML format results in a significantly smaller file size, and that AWS CloudFormation has a hard limit on template file sizes.

Other information

No response

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change
@mckalexee mckalexee added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 27, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Jan 27, 2022
@rix0rrr rix0rrr added effort/medium Medium work item – several days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Feb 8, 2022
@rix0rrr rix0rrr removed their assignment Feb 8, 2022
@mckalexee
Copy link
Author

@rix0rrr FYI, I created a PR for this that's one line.

I can't see any issues with just simply not pretty-printing the file when writing it, but there could be some issue or concern that I'm not aware of.

Thanks!

mergify bot pushed a commit that referenced this issue Apr 1, 2022
also: aws/serverless-application-model#2368, cloudtools/troposphere#2028
#18694
#18886
[CloudFormation templates can currently only be 1MB](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html)

Simply reducing indentation from 2 to 1 should remove ~1/4 of the template file size for everyone by default while still preserving indentation formatting. Beyond improving the default, those wishing to reduce readability for further reduced file size could opt into using something like [`jq`](https://stedolan.github.io/jq/) on their own for now

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
StevePotter pushed a commit to StevePotter/aws-cdk that referenced this issue Apr 27, 2022
also: aws/serverless-application-model#2368, cloudtools/troposphere#2028
aws#18694
aws#18886
[CloudFormation templates can currently only be 1MB](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html)

Simply reducing indentation from 2 to 1 should remove ~1/4 of the template file size for everyone by default while still preserving indentation formatting. Beyond improving the default, those wishing to reduce readability for further reduced file size could opt into using something like [`jq`](https://stedolan.github.io/jq/) on their own for now

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@jesterhazy
Copy link
Contributor

@corymhall i would definitely like to make some progress in this. What did you have in mind?

@mergify mergify bot closed this as completed in #25892 Jun 15, 2023
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*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
3 participants