Skip to content

Commit 6858edf

Browse files
authored
chore(app-staging-synthesizer): reduce the size of DefaultStagingStack template by 5KB (#26024)
Since `DefaultStagingStack` is a stack that creates staging resources, it is bound to the CloudFormation [limit](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html) of 51KB. This means that there is an upper limit on how many ECR repositories (and in turn, unique images) are allowed in the CDK App. In an effort to increase this limit, this PR does the following: - Remove path metadata to save ~2KB - Remove `AWS::CDK::Metadata` construct to save ~3KB - Insert a dummy `UsingDefaultStagingStack` construct to the stacks that _use_ the `DefaultStagingStack` for analytics purposes. In all, this should decrease the size of the DefaultStagingStack template by ~5KB, or ~10% of the overall size allowed. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a8768f4 commit 6858edf

File tree

8 files changed

+56
-8
lines changed

8 files changed

+56
-8
lines changed

packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,27 @@ import {
1717
StackProps,
1818
} from 'aws-cdk-lib/core';
1919
import { StringSpecializer } from 'aws-cdk-lib/core/lib/helpers-internal';
20+
import * as cxapi from 'aws-cdk-lib/cx-api';
21+
import { Construct } from 'constructs';
2022
import { BootstrapRole } from './bootstrap-roles';
2123
import { FileStagingLocation, IStagingResources, IStagingResourcesFactory, ImageStagingLocation } from './staging-stack';
2224

2325
export const DEPLOY_TIME_PREFIX = 'deploy-time/';
2426

27+
/**
28+
* This is a dummy construct meant to signify that a stack is utilizing
29+
* the AppStagingSynthesizer. It does not do anything, and is not meant
30+
* to be created on its own. This construct will be a part of the
31+
* construct tree only and not the Cfn template. The construct tree is
32+
* then encoded in the AWS::CDK::Metadata resource of the stack and
33+
* injested in our metrics like every other construct.
34+
*/
35+
export class UsingAppStagingSynthesizer extends Construct {
36+
constructor(scope: Construct, id: string) {
37+
super(scope, id);
38+
}
39+
}
40+
2541
/**
2642
* User configurable options to the DefaultStagingStack.
2743
*/
@@ -128,6 +144,12 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
128144
throw new Error(`Stack ${stack.stackName} must be part of an App`);
129145
}
130146

147+
// Because we do not keep metrics in the DefaultStagingStack, we will inject
148+
// a dummy construct into the stack using the DefaultStagingStack instead.
149+
if (cxapi.ANALYTICS_REPORTING_ENABLED_CONTEXT) {
150+
new UsingAppStagingSynthesizer(stack, `UsingAppStagingSynthesizer/${stack.stackName}`);
151+
}
152+
131153
const stackId = `StagingStack-${appId}-${context.environmentString}`;
132154
return new DefaultStagingStack(app, stackId, {
133155
...options,
@@ -199,7 +221,10 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
199221
super(scope, id, {
200222
...props,
201223
synthesizer: new BootstraplessSynthesizer(),
224+
analyticsReporting: false, // removing AWS::CDK::Metadata construct saves ~3KB
202225
});
226+
// removing path metadata saves ~2KB
227+
this.node.setContext(cxapi.PATH_METADATA_ENABLE_CONTEXT, false);
203228

204229
this.appId = this.validateAppId(props.appId);
205230
this.dependencyStack = this;

packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ describe(AppStagingSynthesizer, () => {
121121
expect(depStack.stackName).toEqual(`StagingStack-${APP_ID}`);
122122
});
123123

124+
test('stack has dummy construct for metrics', () => {
125+
// WHEN
126+
const dummyConstruct = stack.node.tryFindChild(`UsingAppStagingSynthesizer/${stack.stackName}`);
127+
expect(dummyConstruct).toBeDefined();
128+
});
129+
124130
test('add file asset', () => {
125131
// WHEN
126132
const location = stack.synthesizer.addFileAsset({
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"31.0.0"}
1+
{"version":"32.0.0"}

packages/@aws-cdk/app-staging-synthesizer-alpha/test/integ.synth-default-resources.js.snapshot/integ.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "31.0.0",
2+
"version": "32.0.0",
33
"testCases": {
44
"integ-tests/DefaultTest": {
55
"stacks": [

packages/@aws-cdk/app-staging-synthesizer-alpha/test/integ.synth-default-resources.js.snapshot/integtestsDefaultTestDeployAssert44C8D370.assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "31.0.0",
2+
"version": "32.0.0",
33
"files": {
44
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
55
"source": {

packages/@aws-cdk/app-staging-synthesizer-alpha/test/integ.synth-default-resources.js.snapshot/manifest.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "31.0.0",
2+
"version": "32.0.0",
33
"artifacts": {
44
"synthesize-default-resources.assets": {
55
"type": "cdk:asset-manifest",
@@ -78,6 +78,15 @@
7878
"type": "aws:cdk:logicalId",
7979
"data": "lambdaecr2615DAF68"
8080
}
81+
],
82+
"UsingDefaultStagingStacksynthesizedefaultresources": [
83+
{
84+
"type": "aws:cdk:logicalId",
85+
"data": "UsingDefaultStagingStacksynthesizedefaultresources",
86+
"trace": [
87+
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
88+
]
89+
}
8190
]
8291
},
8392
"displayName": "synthesize-default-resources"

packages/@aws-cdk/app-staging-synthesizer-alpha/test/integ.synth-default-resources.js.snapshot/synthesize-default-resources.assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "31.0.0",
2+
"version": "32.0.0",
33
"files": {
44
"68539effc3f7ad46fff9765606c2a01b7f7965833643ab37e62799f19a37f650": {
55
"source": {

packages/@aws-cdk/app-staging-synthesizer-alpha/test/integ.synth-default-resources.js.snapshot/tree.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
"id": "synthesize-default-resources",
99
"path": "synthesize-default-resources",
1010
"children": {
11+
"UsingAppStagingSynthesizer--synthesize-default-resources": {
12+
"id": "UsingAppStagingSynthesizer--synthesize-default-resources",
13+
"path": "synthesize-default-resources/UsingAppStagingSynthesizer--synthesize-default-resources",
14+
"constructInfo": {
15+
"fqn": "@aws-cdk/app-staging-synthesizer-alpha.UsingAppStagingSynthesizer",
16+
"version": "0.0.0"
17+
}
18+
},
1119
"lambda-s3": {
1220
"id": "lambda-s3",
1321
"path": "synthesize-default-resources/lambda-s3",
@@ -1150,7 +1158,7 @@
11501158
}
11511159
},
11521160
"constructInfo": {
1153-
"fqn": "aws-cdk-lib.Stack",
1161+
"fqn": "@aws-cdk/app-staging-synthesizer-alpha.DefaultStagingStack",
11541162
"version": "0.0.0"
11551163
}
11561164
},
@@ -1167,7 +1175,7 @@
11671175
"path": "integ-tests/DefaultTest/Default",
11681176
"constructInfo": {
11691177
"fqn": "constructs.Construct",
1170-
"version": "10.2.26"
1178+
"version": "10.2.52"
11711179
}
11721180
},
11731181
"DeployAssert": {
@@ -1213,7 +1221,7 @@
12131221
"path": "Tree",
12141222
"constructInfo": {
12151223
"fqn": "constructs.Construct",
1216-
"version": "10.2.26"
1224+
"version": "10.2.52"
12171225
}
12181226
}
12191227
},

0 commit comments

Comments
 (0)