question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cdk synth does not include the metadata in the json generated file

See original GitHub issue

When running cdk synth MyStackName CDKMetadata are shown but not included in the template.json generated file.

We have a simple stack containing 3 parameters and 3 outputs, with no resource. cdk deploy MyStackName works fine

But in a pipeline, CodeBuild will generate the template.json without any resource. Then the CloudFormation action will generate a ValidationException : "errorMessage": "Template format error: At least one Resources member must be defined."

Expected behavior We expect to have the same behavior as cdk deploy command which use the yaml generated template because, in the following template, there is a Resource:

Parameters:
  sdgDomainNameParam:
    Type: String
  sdgDomainCertificateArnParam:
    Type: String
  destinationEnvironmentParam:
    Type: String
Outputs:
  sdgDomainName:
    Description: Domain Name
    Value:
      Ref: sdgDomainNameParam
    Export:
      Name: sdgDomainName
  sdgDomainCertificateArn:
    Description: Domain Certificate Arn
    Value:
      Ref: sdgDomainCertificateArnParam
    Export:
      Name: sdgDomainCertificateArn
  destinationEnvironment:
    Description: destination Environment
    Value:
      Ref: destinationEnvironmentParam
    Export:
      Name: destinationEnvironment
Resources:
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.34.1,@aws-cdk/assets=1.34.1,@aws-cdk/aws-apigateway=1.34.1,@aws-cdk/aws-applicationautoscaling=1.34.1,@aws-cdk/aws-autoscaling-common=1.34.1,@aws-cdk/aws-certificatemanager=1.34.1,@aws-cdk/aws-cloudformation=1.34.1,@aws-cdk/aws-cloudfront=1.34.1,@aws-cdk/aws-cloudwatch=1.34.1,@aws-cdk/aws-cognito=1.34.1,@aws-cdk/aws-dynamodb=1.34.1,@aws-cdk/aws-ec2=1.34.1,@aws-cdk/aws-events=1.34.1,@aws-cdk/aws-iam=1.34.1,@aws-cdk/aws-kms=1.34.1,@aws-cdk/aws-lambda=1.34.1,@aws-cdk/aws-logs=1.34.1,@aws-cdk/aws-s3=1.34.1,@aws-cdk/aws-s3-assets=1.34.1,@aws-cdk/aws-sqs=1.34.1,@aws-cdk/aws-ssm=1.34.1,@aws-cdk/cloud-assembly-schema=1.34.1,@aws-cdk/core=1.34.1,@aws-cdk/custom-resources=1.34.1,@aws-cdk/cx-api=1.34.1,@aws-cdk/region-info=1.34.1,jsii-runtime=node.js/v12.14.1
    Condition: CDKMetadataAvailable
Conditions:
  CDKMetadataAvailable:
    Fn::Or:
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ca-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-northwest-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-central-1
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-2
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-3
          - Fn::Equals:
              - Ref: AWS::Region
              - me-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - sa-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-2
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-2`

Code Snippet

        const sdgDomainName = new CfnParameter(this, 'sdgDomainNameParam').value.toString();
        const sdgDomainCertificateArn = new CfnParameter(this, 'sdgDomainCertificateArnParam').value.toString();
        const sdgDestinationEnvironment = new CfnParameter(this, 'destinationEnvironmentParam').value.toString();

        new CfnOutput(this, "sdgDomainName", {
            description: "Domain Name",
            exportName: 'sdgDomainName',
            value: sdgDomainName
        });

        new CfnOutput(this, "sdgDomainCertificateArn", {
            description: "Domain Certificate Arn",
            exportName: 'sdgDomainCertificateArn',
            value: sdgDomainCertificateArn
        });

        new CfnOutput(this, "destinationEnvironment", {
            description: "destination Environment",
            exportName: 'destinationEnvironment',
            value: sdgDestinationEnvironment
        });

Generated template

{
  "Parameters": {
    "sdgDomainNameParam": {
      "Type": "String"
    },
    "sdgDomainCertificateArnParam": {
      "Type": "String"
    },
    "destinationEnvironmentParam": {
      "Type": "String"
    }
  },
  "Outputs": {
    "sdgDomainName": {
      "Description": "Domain Name",
      "Value": {
        "Ref": "sdgDomainNameParam"
      },
      "Export": {
        "Name": "sdgDomainName"
      }
    },
    "sdgDomainCertificateArn": {
      "Description": "Domain Certificate Arn",
      "Value": {
        "Ref": "sdgDomainCertificateArnParam"
      },
      "Export": {
        "Name": "sdgDomainCertificateArn"
      }
    },
    "destinationEnvironment": {
      "Description": "destination Environment",
      "Value": {
        "Ref": "destinationEnvironmentParam"
      },
      "Export": {
        "Name": "destinationEnvironment"
      }
    }
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shivlakscommented, Aug 7, 2020

@gyurist thanks for that information. I’ll have a look at the logic but I’m bumping this up to a p1.

The behaviour should be consistent regardless of template size.

0reactions
github-actions[bot]commented, Jun 3, 2022

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS CDK Toolkit (cdk command) - AWS Documentation
The AWS CDK Toolkit, the CLI command cdk , is the primary tool for interacting with your AWS CDK app. It executes your...
Read more >
Implement Unit, Integration and Application Test for CDK ...
Let`s apply that to a CDK generated EC2 Load Balancer App. ... This is correct because we do not have a physical resource...
Read more >
Deploy Applications with CDK for Terraform
This is Terraform configuration in JSON format that CDKTF generated based on your TypeScript code in main.ts . Deploy your app. The cdktf...
Read more >
AWS CDK (Cloud Development Kit) – Index - Wilson Mar
NET, NodeJs, or TypeScript code which are synth'd into Cloud Formation or ... The Cloud Development Kit for Terraform (CDKTF) generates JSON ......
Read more >
cdk synth | AWS CDK Workshop
The CDK CLI requires you to be in the same directory as your cdk.json file. If you have changed directories in your terminal,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found