Skip to content

(Aspects): Aspects not applied to Stage; Aspects applied in Stage does not render Annotations #17805

@joel-aws

Description

@joel-aws

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions