Skip to content

Commit

Permalink
appstagingsynth snap
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc committed Jun 20, 2023
2 parents a203c3b + 6858edf commit 555afcf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,27 @@ import {
INLINE_CUSTOM_RESOURCE_CONTEXT,
} from 'aws-cdk-lib/core';
import { StringSpecializer } from 'aws-cdk-lib/core/lib/helpers-internal';
import * as cxapi from 'aws-cdk-lib/cx-api';
import { Construct } from 'constructs';
import { BootstrapRole } from './bootstrap-roles';
import { FileStagingLocation, IStagingResources, IStagingResourcesFactory, ImageStagingLocation } from './staging-stack';

export const DEPLOY_TIME_PREFIX = 'deploy-time/';

/**
* This is a dummy construct meant to signify that a stack is utilizing
* the AppStagingSynthesizer. It does not do anything, and is not meant
* to be created on its own. This construct will be a part of the
* construct tree only and not the Cfn template. The construct tree is
* then encoded in the AWS::CDK::Metadata resource of the stack and
* injested in our metrics like every other construct.
*/
export class UsingAppStagingSynthesizer extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
}
}

/**
* User configurable options to the DefaultStagingStack.
*/
Expand Down Expand Up @@ -137,6 +153,12 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
throw new Error(`Stack ${stack.stackName} must be part of an App`);
}

// Because we do not keep metrics in the DefaultStagingStack, we will inject
// a dummy construct into the stack using the DefaultStagingStack instead.
if (cxapi.ANALYTICS_REPORTING_ENABLED_CONTEXT) {
new UsingAppStagingSynthesizer(stack, `UsingAppStagingSynthesizer/${stack.stackName}`);
}

const stackId = `StagingStack-${appId}-${context.environmentString}`;
return new DefaultStagingStack(app, stackId, {
...options,
Expand Down Expand Up @@ -209,7 +231,10 @@ export class DefaultStagingStack extends Stack implements IStagingResources {
super(scope, id, {
...props,
synthesizer: new BootstraplessSynthesizer(),
analyticsReporting: false, // removing AWS::CDK::Metadata construct saves ~3KB
});
// removing path metadata saves ~2KB
this.node.setContext(cxapi.PATH_METADATA_ENABLE_CONTEXT, false);

// For all resources under the default staging stack, we want to inline custom
// resources because the staging bucket necessary for custom resource assets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ describe(AppStagingSynthesizer, () => {
expect(depStack.stackName).toEqual(`StagingStack-${APP_ID}`);
});

test('stack has dummy construct for metrics', () => {
// WHEN
const dummyConstruct = stack.node.tryFindChild(`UsingAppStagingSynthesizer/${stack.stackName}`);
expect(dummyConstruct).toBeDefined();
});

test('add file asset', () => {
// WHEN
const location = stack.synthesizer.addFileAsset({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
"type": "aws:cdk:logicalId",
"data": "lambdaecr2615DAF68"
}
],
"UsingDefaultStagingStacksynthesizedefaultresources": [
{
"type": "aws:cdk:logicalId",
"data": "UsingDefaultStagingStacksynthesizedefaultresources",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
]
},
"displayName": "synthesize-default-resources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"id": "synthesize-default-resources",
"path": "synthesize-default-resources",
"children": {
"UsingAppStagingSynthesizer--synthesize-default-resources": {
"id": "UsingAppStagingSynthesizer--synthesize-default-resources",
"path": "synthesize-default-resources/UsingAppStagingSynthesizer--synthesize-default-resources",
"constructInfo": {
"fqn": "@aws-cdk/app-staging-synthesizer-alpha.UsingAppStagingSynthesizer",
"version": "0.0.0"
}
},
"lambda-s3": {
"id": "lambda-s3",
"path": "synthesize-default-resources/lambda-s3",
Expand Down

0 comments on commit 555afcf

Please sign in to comment.