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

Aspects are not always applied to resource created by Aspects #7049

Closed
NetaNir opened this issue Mar 27, 2020 · 2 comments
Closed

Aspects are not always applied to resource created by Aspects #7049

NetaNir opened this issue Mar 27, 2020 · 2 comments
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. p1

Comments

@NetaNir
Copy link
Contributor

NetaNir commented Mar 27, 2020

Resource can be created via aspects and they will be added to the construct tree during the invokeAspects phase in prepare. Since aspects are applied to a scope, it is possible that the a resource created via aspect will be created in a scope that has other aspects applied. However, whether these aspects will be invoked on the newly created resource depends on the order of aspects invocation.
An easy example to think of to fully understand the problem are Tags, which are implemented using aspects. Lets say that I want to tag all of the resource in my application with foo:bar:

const root = new App();
root.node.applyAspect(new Tag('foo', 'bar')); //adds the tag to all taggable  resources under root 
const stack = new Stack(root, 'MyStack');
const resourceA = new Construct(stack, 'ResourceA');
// TaggableResource is a resource that can be tagged
new TaggableResource(resource, 'Resource', {
  type: 'AWS::Fake::Thing',
});

Additionally, I would like to apply MyAspect that creates a resource to resourceA:

class MyAspect implements IAspect {
  public visit(node: Construct): void {
    new TaggableResource(node, `${node.node.id}-AspectAdded`, {
      type: 'AWS::Fake::Aspect::Thing:',
    });
  }
}

Apply MyAspect to resourceA:

resourceA.node.applyAspect(new MyAspect());

Since aspects are applied root to leaves, the newly created resource will not be tagged since it was created after the tag aspect has been invoked.

Environment

  • CLI Version 1.31 :
  • Framework Version: 1.31

Other


This is 🐛 Bug Report

@NetaNir NetaNir added bug This issue is a bug. @aws-cdk/core Related to core CDK functionality labels Mar 27, 2020
@eladb eladb added the p1 label Mar 31, 2020
@eladb eladb removed their assignment Aug 4, 2020
@NetaNir
Copy link
Contributor Author

NetaNir commented Feb 25, 2021

closed #8639

@NetaNir NetaNir closed this as completed Feb 25, 2021
@github-actions
Copy link

⚠️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.

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. p1
Projects
None yet
Development

No branches or pull requests

2 participants