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

feat(core): allow disabling of LogicalID Metadata in case of large manifest #20433

Merged
merged 13 commits into from
May 20, 2022
5 changes: 4 additions & 1 deletion packages/@aws-cdk/core/lib/cfn-element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as cxschema from '@aws-cdk/cloud-assembly-schema';
import * as cxapi from '@aws-cdk/cx-api';
import { Construct, Node } from 'constructs';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
Expand Down Expand Up @@ -64,7 +65,9 @@ export abstract class CfnElement extends CoreConstruct {
displayHint: `${notTooLong(Node.of(this).path)}.LogicalID`,
});

Node.of(this).addMetadata(cxschema.ArtifactMetadataEntryType.LOGICAL_ID, this.logicalId, this.constructor);
if (!this.node.tryGetContext(cxapi.DISABLE_LOGICAL_ID_METADATA)) {
Node.of(this).addMetadata(cxschema.ArtifactMetadataEntryType.LOGICAL_ID, this.logicalId, this.constructor);
}
}

/**
Expand Down
51 changes: 46 additions & 5 deletions packages/@aws-cdk/core/test/synthesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as os from 'os';
import * as path from 'path';
import { testDeprecated } from '@aws-cdk/cdk-build-tools';
import * as cxschema from '@aws-cdk/cloud-assembly-schema';
import * as cxapi from '@aws-cdk/cx-api';
import * as cdk from '../lib';

function createModernApp() {
Expand Down Expand Up @@ -36,7 +37,6 @@ describe('synthesis', () => {
},
}),
});

});

test('synthesis respects disabling tree metadata', () => {
Expand All @@ -45,7 +45,52 @@ describe('synthesis', () => {
});
const assembly = app.synth();
expect(list(assembly.directory)).toEqual(['cdk.out', 'manifest.json']);
});

test('synthesis respects disabling logicalId metadata', () => {
const app = new cdk.App({
context: {
[cxapi.DISABLE_LOGICAL_ID_METADATA]: true,
},
});
const stack = new cdk.Stack(app, 'one-stack');
new cdk.CfnResource(stack, 'MagicResource', { type: 'Resource::Type' });

// WHEN
const session = app.synth();

// THEN
expect(Object.keys((session.manifest.artifacts ?? {})['one-stack'])).not.toContain('metadata');
});

test('synthesis respects disabling logicalId metadata, and does not disable other metadata', () => {
const app = new cdk.App({
context: {
[cxapi.DISABLE_LOGICAL_ID_METADATA]: true,
},
stackTraces: false,
});
const stack = new cdk.Stack(app, 'one-stack', { tags: { boomTag: 'BOOM' } });
new cdk.CfnResource(stack, 'MagicResource', { type: 'Resource::Type' });

// WHEN
const session = app.synth();

// THEN
expect(session.manifest.artifacts?.['one-stack'].metadata).toEqual({
'/one-stack': [
{
type: 'aws:cdk:stack-tags',
data: [
{
key: 'boomTag',
value: 'BOOM',
},
],
},
],
// no logicalId entry
});
});

test('single empty stack', () => {
Expand All @@ -58,7 +103,6 @@ describe('synthesis', () => {

// THEN
expect(list(session.directory).includes('one-stack.template.json')).toEqual(true);

});

test('some random construct implements "synthesize"', () => {
Expand Down Expand Up @@ -112,7 +156,6 @@ describe('synthesis', () => {
},
},
});

});

test('random construct uses addCustomSynthesis', () => {
Expand Down Expand Up @@ -172,7 +215,6 @@ describe('synthesis', () => {
},
},
});

});

testDeprecated('it should be possible to synthesize without an app', () => {
Expand Down Expand Up @@ -220,7 +262,6 @@ describe('synthesis', () => {
expect(stack.templateFile).toEqual('hey.json');
expect(stack.parameters).toEqual({ paramId: 'paramValue', paramId2: 'paramValue2' });
expect(stack.environment).toEqual({ region: 'us-east-1', account: 'unknown-account', name: 'aws://unknown-account/us-east-1' });

});
});

Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/cx-api/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export const DISABLE_ASSET_STAGING_CONTEXT = 'aws:cdk:disable-asset-staging';
*/
export const DISABLE_METADATA_STACK_TRACE = 'aws:cdk:disable-stack-trace';

/**
* If this context key is set, the CDK will not store logical ID
* metadata in the manifest.
*/
export const DISABLE_LOGICAL_ID_METADATA = 'aws:cdk:disable-logicalId-metadata';

/**
* Run bundling for stacks specified in this context key
*/
Expand Down