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): Aspects not applied to Stage; Aspects applied in Stage does not render Annotations #17805

Open
joel-aws opened this issue Dec 1, 2021 · 4 comments
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 p2

Comments

@joel-aws
Copy link
Contributor

joel-aws commented Dec 1, 2021

What is the problem?

  • Aspects are not being applied to Stages in an App.
  • Aspects applied within a Stage do not produce Annotation output.

Reproduction Steps

import jsii
from monocdk import (
    App,
    Annotations,
    Aspects,
    Duration,
    Stack,
    Stage,
    Construct,
    IAspect,
    aws_sns as sns,
    aws_sqs as sqs,
    aws_sns_subscriptions as subs,
)

from monocdk_nag import AwsSolutionsChecks

app = App()


class TestStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        queue = sqs.Queue(
            self,
            "DelMeNowQueue",
            visibility_timeout=Duration.seconds(300),
        )

        topic = sns.Topic(self, "DelMeNowTopic")

        topic.add_subscription(subs.SqsSubscription(queue))


@jsii.implements(IAspect)
class NonsenseSQSAspect:
    def visit(self, node):
        if isinstance(node, sqs.Queue):
            print("nonsense")


@jsii.implements(IAspect)
class NonsenseSQSErrorAspect:
    def visit(self, node):
        if isinstance(node, sqs.Queue):
            Annotations.of(node).add_error("foo")


class ApplicationStage(Stage):
    def __init__(
        self,
        scope: Construct,
        id: str,
        **kwargs,
    ):
        super().__init__(scope, id, **kwargs)

        stack = TestStack(self, "test")

        Aspects.of(self).add(AwsSolutionsChecks())  # Test 4 -- Doesn't print output, applies the aspect
        Aspects.of(self).add(NonsenseSQSAspect())  # Test 5 -- Prints output, applies the aspect
        Aspects.of(self).add(NonsenseSQSErrorAspect())  # Test 6 -- Doesn't print output, applies the aspect


stage = ApplicationStage(app, "stage")

Aspects.of(app).add(AwsSolutionsChecks())  # Test 1 -- Doesn't print output or apply the aspect
Aspects.of(app).add(NonsenseSQSAspect())  # Test 2 -- Doesn't print output or apply the aspect
Aspects.of(app).add(NonsenseSQSErrorAspect())  # Test 3 -- Doesn't print output or apply the aspect

app.synth()

What did you expect to happen?

  • Tests 1-3: Aspects to be applied to the Stage in the App and Annotations to produce output.
  • Tests 1 & 4: output from Annotations in Aspects.

What actually happened?

See: What is the problem

CDK CLI Version

1.134.0 (build dd5e12d)

Framework Version

No response

Node.js Version

v16.3.0

OS

macOS 11.5.1

Language

Python

Language Version

No response

Other information

Might be related to #17210 .

@joel-aws joel-aws added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 1, 2021
@github-actions github-actions bot added the @aws-cdk/aws-sqs Related to Amazon Simple Queue Service label Dec 1, 2021
@ryparker ryparker added effort/small Small work item – less than a day of effort needs-reproduction This issue needs reproduction. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 2, 2021
@joel-aws
Copy link
Contributor Author

joel-aws commented Dec 7, 2021

Update: with Aspects applied in a Stage (examples 4-6), annotations do appear during a cdk deploy; they do not appear during a cdk synth.

@njlynch njlynch added @aws-cdk/core Related to core CDK functionality and removed @aws-cdk/aws-sqs Related to Amazon Simple Queue Service labels Dec 29, 2021
@njlynch njlynch removed their assignment Dec 29, 2021
@github-actions
Copy link

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.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Dec 29, 2022
@joel-aws
Copy link
Contributor Author

Judging by the linked activity, this issue should remain open.

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Dec 29, 2022
@IsmaelMartinez
Copy link
Contributor

I think this is related to #21341 (or the same underlying issue). My aspects don't work anymore when using Stages that have multiple stacks. I wonder if that is because the for loop that finds the children.

for (const child of construct.node.children) {

As looks like the aspects only iterate throw the Stages, but not beyond that. I will see if I find anything else.

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 p2
Projects
None yet
5 participants