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

aws_cdk.Annotations: annotations not applied if using stages #22507

Closed
pwrmiller opened this issue Oct 14, 2022 · 4 comments
Closed

aws_cdk.Annotations: annotations not applied if using stages #22507

pwrmiller opened this issue Oct 14, 2022 · 4 comments
Assignees
Labels
package/tools Related to AWS CDK Tools or CLI

Comments

@pwrmiller
Copy link

pwrmiller commented Oct 14, 2022

Describe the bug

Annotations are not applied when a Stack is deployed as part of a Stage. This seems to be related to #9799.

This in turn was a duplicate of #8676 which was closed as fixed, but the annotation processing is not applied as demonstrable by the code snippet below.

This is on CDK 2.46.0 (build 5a0595e).

Expected Behavior

I expected to see the annotations in the CDK Synth output

cdk synth 
[Error at /Stage-WorkingStack] this will not appear

Found errors

Current Behavior

I observe no annotations (warnings, info, error) when using stacks deployed as part of a pipeline

cdk synth 
Successfully synthesized to /Users/paulmiller/Design/wfo-codedeploy/cdk.out
Supply a stack id () to display its template.

Reproduction Steps

app.py

import aws_cdk as cdk
from constructs import Construct


class Stack(cdk.Stack):
    def __init__(self, scope: Construct, construct_id: str):
        super().__init__(scope, construct_id)

        cdk.Annotations.of(self).add_error("this will not appear when called from a stage")


def ok():
    app = cdk.App()
    stack = Stack(app, "WorkingStack")
    return app.synth()


def fails():
    app = cdk.App()
    stage = cdk.Stage(app, "Stage")
    stack = Stack(stage, "FailingStack")
    return app.synth()


if __name__ == "__main__":
    fails()

cdk.json

{
  "app": "python3 app.py"
}

Running this with cdk synth will show no annotation when running the fails() app. Running the ok() app works.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.46.0 (build 5a0595e)

Framework Version

No response

Node.js Version

v18.10.0

OS

MacOS Monterey

Language

Python

Language Version

Python (3.10.6)

Other information

No response

@pwrmiller pwrmiller added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 14, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Oct 14, 2022
@peterwoodworth
Copy link
Contributor

Thanks for opening this issue @pwrmiller,

This is happening because you aren't actually synthing the stack inside the stage with cdk synth. Since the stack is inside a stage, it isn't a top level stack which means it's not going to synthesize unless specified. To truly specify all stacks, you can run cdk synth '**', or you can specify the stack in your stage like cdk synth Stage/*. Both of these will produce the error when ran 🙂

To see more information on specifying stacks, see the documentation here

@peterwoodworth peterwoodworth removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 19, 2022
@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.

@dontirun
Copy link
Contributor

@peterwoodworth Is the prepare phase for a stack within a Stage run with a bare cdk synth?

Context:
Trying to understand the behavior in this cdk-nag issue cdklabs/cdk-nag#637

@peterwoodworth
Copy link
Contributor

peterwoodworth commented Nov 10, 2022

If the stack isn't specified it's going to be completely ignored @dontirun. You need to specify the stack as I've indicated above - top level stages are not synthesized by default. That issue you've linked just looks to me like they need to actually specify the stack (like in my above comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

4 participants