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

[core] CfnMapping creates wrong mappings #9432

Closed
beomseoklee opened this issue Aug 4, 2020 · 1 comment · Fixed by #9451
Closed

[core] CfnMapping creates wrong mappings #9432

beomseoklee opened this issue Aug 4, 2020 · 1 comment · Fixed by #9451
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p2

Comments

@beomseoklee
Copy link

beomseoklee commented Aug 4, 2020

CfnMapping creates wrong CFN mappings. It should not add Mappings twice.

Please let me know if any other information is needed or I did something wrong.

Reproduction Steps

import * as cdk from '@aws-cdk/core';

export class CDKStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    new cdk.CfnMapping(this, 'Mappings', {
      mapping: {
        Map: {
          This: {
            One: 'Yes'
          }
        }
      }
    });
  }
}

With that code, when I cdk synth --asset-metadata false --path-metadata false --version-reporting false --json true, it created wrong mappings.

What did you expect to happen?

{
  "Mappings": {
    "Map": {
      "This": {
        "One": "Yes"
      }
    }
  }
}

What actually happened?

{
  "Mappings": {
    "Mappings": {
      "Map": {
        "This": {
          "One": "Yes"
        }
      }
    }
  }
}

Environment

  • CLI Version : 1.54.0
  • Framework Version: 1.54.0
  • Node.js Version: 12.13.1
  • OS : OSX Mojave
  • Language (Version): TypeScript (3.9.6)

This is 🐛 Bug Report

@beomseoklee beomseoklee added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 4, 2020
@SomayaB SomayaB changed the title [CfnMapping] CfnMapping creates wrong mappings [core] CfnMapping creates wrong mappings Aug 5, 2020
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Aug 5, 2020
eladb pushed a commit that referenced this issue Aug 5, 2020
Add the synthesized template output as an example to make sure it's clear that `CfnMapping` represents a single mapping entry and not the entire `Mappings` section in the template.

Fixes #9432
@eladb
Copy link
Contributor

eladb commented Aug 5, 2020

Each CfnMapping (singular) object represents a single entry in your template's Mappings section (plural). This way, you can define multiple mappings by simply creating multiple instances of CfnMapping.

The id of the CfnMapping construct will be used as the ID of the mapping.

import * as cdk from '@aws-cdk/core';

export class CDKStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new cdk.CfnMapping(this, 'Map1', {
      mapping: {
        This: {
          One: 'Yes'
        }
      }
    });

    new cdk.CfnMapping(this, 'Map'2, {
      mapping: {
        Hello: 'world'
      }
    });
  }
}

Will yield:

{
  "Mappings": {
    "Map1": {
      "This": {
        "One": "Yes"
      }
    },
    "Map2": {
      "Hello": "World"
    }
  }
}

I've created a PR to update the docs to make it a bit clearer: #9451

@eladb eladb added p2 effort/small Small work item – less than a day of effort labels Aug 5, 2020
@mergify mergify bot closed this as completed in #9451 Aug 5, 2020
mergify bot pushed a commit that referenced this issue Aug 5, 2020
Add the synthesized template output as an example to make sure it's clear that `CfnMapping` represents a single mapping entry and not the entire `Mappings` section in the template.

Fixes #9432


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
eladb pushed a commit that referenced this issue Aug 10, 2020
Add the synthesized template output as an example to make sure it's clear that `CfnMapping` represents a single mapping entry and not the entire `Mappings` section in the template.

Fixes #9432


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
curtiseppel pushed a commit to curtiseppel/aws-cdk that referenced this issue Aug 11, 2020
Add the synthesized template output as an example to make sure it's clear that `CfnMapping` represents a single mapping entry and not the entire `Mappings` section in the template.

Fixes aws#9432


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants