Aws-cdk: Cryptic error message when stack tags use late-bound values

Created on 28 Jan 2020  ยท  3Comments  ยท  Source: aws/aws-cdk

When trying to add tags to a stack, I'm receiving the following error:
โŒ MyStack failed: InvalidParameterType: Expected params.Tags[0].Value to be a string

Reproduction Steps

Here is how I'm adding tags:

const stack = new AccountSetupStack(app, 'AccountSetupStack', {
    "description": "Account setup"
});
stack.tags.setTag("StackName", cdk.Aws.STACK_NAME, 0, true)

Adding tags directly to the stack also produces the same error:

const stack = new AccountSetupStack(app, 'AccountSetupStack', {
    "description": "Account setup",
    "tags": {
        "StackName": cdk.Aws.STACK_NAME
    }
});
stack.tags.setTag("StackName", cdk.Aws.STACK_NAME, 0, true)

Environment

  • **CLI Version : 1.22.0 (build 309ac1b)
  • **Language : Typescript

This is :bug: Bug Report

@aws-cdcore bug p2

All 3 comments

CloudFormation stack tags are applied upon stack creation and not during deployment and therefore they cannot use pseudo parameters like Aws.STACK_NAME.

You can use stack.stackName instead, which is early-bound:

stack.tags.setTag('StackName', stack.stackName);

We should add a validation that will emit a more informative error.

Thanks for explanation. I'm truly learning a lot here.

I'd say @eladb answer resolves the issue. Thanks!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slipdexic picture slipdexic  ยท  3Comments

sudoforge picture sudoforge  ยท  3Comments

ababra picture ababra  ยท  3Comments

v-do picture v-do  ยท  3Comments

artyom-melnikov picture artyom-melnikov  ยท  3Comments