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.

[aws-resourcegroups] aws-resourcegroups requires an array for tags property but fails CFN stack creation with internal error

See original GitHub issue

description of the bug:

When adding tags to resource groups I am getting this error:

Error: Invalid tag input expected map of {key: value} have [{"Key":"TagKey","Value":"TagValue"}]
    at MapFormatter.parseTags (/Users/amawalte/Downloads/cdk/EBS-SSMMaintenanceWindows/node_modules/@aws-cdk/core/lib/tag-manager.js:81:19)

because the error keeps saying expects map of {key: value} I passed the tags like this:

const rgTags = 
            {
                "Key": "Key",
                "Value": "Value"
            }

This allowed me to get passed the CDK error, and it started creating the stack, however it failed with the internal error:

✗ sudo cdk deploy --app ssm_maintenance_windows.js EBS-resource-groups-stack
EBS-resource-groups-stack: deploying...
EBS-resource-groups-stack: creating CloudFormation changeset...
 0/4 | 12:41:01 PM | CREATE_IN_PROGRESS   | AWS::ResourceGroups::Group | RDS-SIT (RDSSIT)
 0/4 | 12:41:01 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata         | CDKMetadata
 0/4 | 12:41:01 PM | CREATE_IN_PROGRESS   | AWS::ResourceGroups::Group | EC2-SIT (EC2SIT)
 1/4 | 12:41:02 PM | CREATE_FAILED        | AWS::ResourceGroups::Group | RDS-SIT (RDSSIT) Internal Failure
    ResourceGroupStack.createResourceGroup (/Users/Amanda/Downloads/cdk/EBS-SSMMaintenanceWindows/lib/resource_groups_stack.js:18:16)
    \_ /Users/Amanda/Downloads/cdk/EBS-SSMMaintenanceWindows/lib/resource_groups_stack.js:14:43
    \_ Array.forEach (<anonymous>)
    \_ new ResourceGroupStack (/Users/Amanda/Downloads/cdk/EBS-SSMMaintenanceWindows/lib/resource_groups_stack.js:13:27)
    \_ Object.<anonymous> (/Users/Amanda/Downloads/cdk/EBS-SSMMaintenanceWindows/bin/ssm_maintenance_windows.js:10:28)
    \_ Module._compile (internal/modules/cjs/loader.js:1200:30)
    \_ Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    \_ Module.load (internal/modules/cjs/loader.js:1049:32)
    \_ Function.Module._load (internal/modules/cjs/loader.js:937:14)
    \_ Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    \_ internal/main/run_main_module.js:17:47
 2/4 | 12:41:02 PM | CREATE_FAILED        | AWS::ResourceGroups::Group | EC2-SIT (EC2SIT) Internal Failure

So I opened the cloudformation stack in designer and changed from:

This:

"Tags": {
                    "Key": "Key",
                    "Value": "Value"
                }

To This:

"Tags": [
                    {
                        "Key": "Key",
                        "Value": "Value"
                    }
                ]

And it created successfully. So, to double check, I went back to the cdk app and changed the code to match what was successful in cloudformation:

class ResourceGroupStack extends cdk.Stack {
    constructor(scope, id, resourceGroupList) {
        super(scope, id);
        this.resourceGroups = [];
        const rgTags = [
            {
                "Key": "TagKey",
                "Value": "TagValue"
            }
        ]

And it errored out again:

Error: Invalid tag input expected map of {key: value} have [{"Key":"TagKey","Value":"TagValue"}]
    at MapFormatter.parseTags (/Users/amawalte/Downloads/cdk/EBS-SSMMaintenanceWindows/node_modules/@aws-cdk/core/lib/tag-manager.js:81:19)

Based on the above tests, CDK will not take the array, even though that is the only acceptable format for aws::resourcegroups::group . To verify, I checked the cdk code:

class MapFormatter {
    parseTags(cfnPropertyTags, priority) {
        const tags = [];
        if (Array.isArray(cfnPropertyTags) || typeof (cfnPropertyTags) !== 'object') {
            throw new Error(`Invalid tag input expected map of {key: value} have ${JSON.stringify(cfnPropertyTags)}`);
        }
        for (const [key, value] of Object.entries(cfnPropertyTags)) {
            tags.push({
                key,
                value: `${value}`,
                priority
            });

The above seems to indicate if it it is an array to throw the above error. Ref: https://github.com/aws/aws-cdk/pull/1762/files MapFormatter is the funciton that throws the error based on the output .

Environment

  • CLI Version aws --version aws-cli/1.17.10 Python/2.7.16 Darwin/18.7.0 botocore/1.14.10 :
  • Framework Version: cdk --version 1.42.0 (build 3b64241)
  • Node.js Version: ~ node -v v14.3.0
  • OS Mojave 10.14.6 :
  • Language (Version):

This is 🐛 Bug Report

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
eladbcommented, Jul 14, 2020

Until this is resolved, you can use addPropertyOverride to apply the tag to the CFN resource like so:

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

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

    const group = new rg.CfnGroup(this, 'MyGroup', {
      name: 'mygroup'
    });

    group.addPropertyOverride('Tags', [
      {
        Key: 'Mykey',
        Value: 'MyValue'
      }
    ]);
  }
}

This will produce the following template:

{
  "Resources": {
    "MyGroup": {
      "Type": "AWS::ResourceGroups::Group",
      "Properties": {
        "Name": "mygroup",
        "Tags": [
          {
            "Key": "Mykey",
            "Value": "MyValue"
          }
        ]
      },
      "Metadata": {
        "aws:cdk:path": "Repro9040Stack/MyGroup"
      }
    }
  }
}
0reactions
github-actions[bot]commented, Aug 1, 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

Resolve the "Internal Failure" error in CloudFormation
If you're creating or updating your CloudFormation stack, you can receive an "Internal Failure" error when an operation on a resource fails.
Read more >
create-group — AWS CLI 2.9.4 Command Reference
Creates a resource group with the specified name and description. You can optionally include a resource query, or a service configuration. For more...
Read more >
awscdk - Go Packages
The AWS CDK construct library provides APIs to define your CDK application and add CDK constructs to the application. Usage.
Read more >
CHANGELOG.txt 3.3.485.0 - PowerShell Gallery
[Breaking Change] Fixed a bug in Test-CFNStack causing the cmdlet to throw an ... and Submit-DFTestRun allowing to schedule runs without a need...
Read more >
AWS equivalent for Azure Resourcegroup - Stack Overflow
But it will work for your need. You need to use tags for the resources and then group them using AWS Resource Groups....
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