aws / aws/aws-cdk

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

Open
#17,805 5 comments 9 reactions 0 assignees View on GitHub
@aws-cdk/core bug effort/small p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### 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

```python
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 .

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied Python reproduction with app.synth(), comparing Aspects.of(app) and Aspects.of(stage) for the three annotation and aspect cases. Trace the App, Stage, Aspects, and Annotations entry points named in the example. Done means aspects attached at both scopes visit the expected constructs and annotations produce output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.