aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.58k stars 3.88k forks source link

(core): Error when tagging a stack with S3 bucket #16647

Closed leantorres73 closed 3 years ago

leantorres73 commented 3 years ago

Setting a tag in a stack, where the stack creates an S3 bucket is throwing an error:

/home/leandro/company/vector-application-api/node_modules/@aws-cdk/core/lib/aspect.js:43
        this.scope.node._actualNode.applyAspect(aspect);
                        ^

TypeError: Cannot read property '_actualNode' of undefined
    at Aspects.add (/home/leandro/company/vector-application-api/node_modules/@aws-cdk/core/lib/aspect.js:43:25)
    at Tags.add (/home/leandro/company/vector-application-api/node_modules/@aws-cdk/core/lib/tag-aspect.js:101:41)

Digging a little more in the issue, it looks like this.scope does not have node, but it has the bucket as a children. So if I console log this.scope before it fails I see this:

{
  patientAttachments: Bucket {
    node: ConstructNode { host: [Circular], _actualNode: [Node] },
    stack: DeploymentStack {
      node: [ConstructNode],
      _missingContext: [],
      _stackDependencies: {},
      templateOptions: {},
      ...
      [Symbol(@aws-cdk/core.DependableTrait)]: [Object]
    },
    env: { account: '...', region: '...' },
      ...
      [Symbol(@aws-cdk/core.DependableTrait)]: [Object]
    },
    ...
    disallowPublicAccess: true,
    accessControl: undefined,
    policy: BucketPolicy {
      ...
  }
}

This means it will never find node attribute because it's one level down.

Reproduction Steps

Create a Stack, then try to add a tag like this:

cdk.Tags.of(deploymentStack).add('tagname', 'tagvalue');

What did you expect to happen?

It should set a tag for each element inside the stack with no issues

What actually happened?

When the Stack contains an S3 bucket creation, it fails with the error mentioned above

Environment


This is :bug: Bug Report

rix0rrr commented 3 years ago

I'm going to guess the source for this is around versions of the cdk project and the constructs library.

Looks like you're using NPM. Can I see your package.json ?

leantorres73 commented 3 years ago

dev dependencies:

"devDependencies": {
        "@aws-cdk/assert": "1.123.0",
        "@aws-cdk/aws-appconfig": "1.123.0",
        "@aws-cdk/aws-certificatemanager": "1.123.0",
        "@aws-cdk/aws-codebuild": "1.123.0",
        "@aws-cdk/aws-codepipeline": "1.123.0",
        "@aws-cdk/aws-codepipeline-actions": "1.123.0",
        "@aws-cdk/aws-codestarnotifications": "1.123.0",
        "@aws-cdk/aws-ec2": "1.123.0",
        "@aws-cdk/aws-elasticbeanstalk": "1.123.0",
        "@aws-cdk/aws-iam": "1.123.0",
        "@aws-cdk/aws-route53": "1.123.0",
        "@aws-cdk/aws-s3": "1.123.0",
        "@aws-cdk/aws-s3-assets": "1.123.0",
        "@aws-cdk/aws-secretsmanager": "1.123.0",
        "@aws-cdk/aws-ssm": "1.123.0",
        "@aws-cdk/core": "1.123.0",
        "@aws-cdk/pipelines": "1.123.0",
        "aws-cdk": "1.123.0",
        "eslint": "^6.5.1",
        "eslint-config-prettier": "^6.4.0",
        "eslint-plugin-jest": "^24.1.0",
        "eslint-plugin-node": "^10.0.0",
        "eslint-plugin-prettier": "^3.1.1",
        "factory-girl": "^5.0.4",
        "fake": "^0.2.2",
        "husky": "^6.0.0",
        "jest": "^26.6.0",
        "nodemon": "1.19.1",
        "prettier": "^1.18.2",
        "vr-cdk-utils": "1.5.7"
    },

and I'm trying to add a tag to the stack

cdk.Tags.of(deploymentStack).add(
            'Description',
            'Resource Description'
        );

The main problem is that if I remove the creation of the S3 bucket from the stack it works, when adding the bucket it does not. The creation of the stack is inside a pipeline stage

leantorres73 commented 3 years ago

Sorry about wasting your time, I found out that I was doing a return in the Stack constructor, that means the constructor was returning something else than expected and that was failing

github-actions[bot] commented 3 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.