How to turn off Metadata Reporting in AWS CDK

avatar

Borislav Hadzhiev

Fri Apr 23 20212 min read

Updated on Fri Apr 23 2021

Turn off CDK Metadata globally #

To shave off a couple of lines from our CloudFormation templates, we can opt of our metadata reporting.

Metadata is used by the CDK team in order to collect analytics in regards to how developers use the CDK service.

If we want to disable version reporting for all commands we issue on the CDK app level, we can edit the contents of our cdk.json file and set the versionReporting key to false:

cdk.json
{ "app": "npx ts-node --prefer-ts-exts infra/app.ts", "versionReporting": false }

If we now check the contents of the CloudFormation template in the cdk.out directory, we can see that the CDKMetadata section has been removed:

cdk out no metadata

Also if we issue the cdk synth command we won't see the CDKMetadata section anymore:

cdk synth no metadata

Turn off Metadata for a single command #

We can also opt out of metadata reporting for a single command, by adding the --no-version-reporting flag to the cdk deploy command:

shell
npx cdk --no-version-reporting deploy

By taking the --no-version-reporting flag approach you would have to include the flag every time you issue a synth or deploy command, so the versionReporting boolean in the cdk.json file is the more convenient option.

What is Metadata #

Metadata is a CloudFormation feature, that allows us to specify additional details about our template using json or yaml.

Metadata is used by the CDK team in order to collect analytics in regards to how developers use the CDK service.

When we run the cdk synth command we see the CloudFormation template equivalent to our CDK code.

At the bottom of the template we can see the CDKMetadata section, that looks something like:

CDKMetadata: Type: AWS::CDK::Metadata Properties: Analytics: v2:deflate64:H4sIAAAAAAA... Metadata: aws:cdk:path: my-cdk-stack/CDKMetadata/Default

If we look at the CloudFormation template stored in the cdk.out directory, we can also see the CDKMetadata section:

cdk.out/my-cdk-stack.template.json
{ "CDKMetadata": { "Type": "AWS::CDK::Metadata", "Properties": { "Analytics": "v2:deflate64:H4sIAAAA..." }, "Metadata": { "aws:cdk:path": "my-cdk-stack/CDKMetadata/Default" } } }

cdk out metadata

According to the docs, the CDK team collects data about what constructs developers use in order to gain insight and notify customers who are using constructs with security vulnerabilities.

Further Reading #

Add me on LinkedIn

I'm a Web Developer with TypeScript, React.js, Node.js and AWS experience.

Let's connect on LinkedIn

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee