Skip to content

Adding an aspect to Bucket with S3 notifications leads to an error #33943

Closed
@Dreamescaper

Description

@Dreamescaper

Describe the bug

In our setup we use an aspect, which adds common tags to most of the resources (like "Name" tag).
Unfortunately, this aspect stopped working after update to 2.181.0 .

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

2.180.0

Expected Behavior

Tags should be applied, CDK should be executed successfully.

Current Behavior

'Error: Cannot invoke Aspect Tag with priority 200 on node CdkReproStack/test-bucket/Notifications: an Aspect Object with a lower priority (500) was already invoked on this node.'

Reproduction Steps

    public class CdkReproStack : Stack
    {
        internal CdkReproStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            var bucket = new Bucket(this, "test-bucket", new BucketProps
            {
                BucketName = "test-bucket"
            });

            var function = new Function(this, "test-function", new FunctionProps
            {
                FunctionName = "test-function",
                Handler = "handler",
                Runtime = Runtime.NODEJS_22_X,
                Code = Code.FromInline("function(){ }")
            });

            function.AddEventSource(new S3EventSourceV2(bucket, new S3EventSourceProps
            {
                Events = [EventType.OBJECT_CREATED]
            }));

            Aspects.Of(this).Add(new TagNameAspect(), new AspectOptions { Priority = 10 });
        }
    }

    class TagNameAspect : Amazon.JSII.Runtime.Deputy.DeputyBase, IAspect
    {
        public void Visit(IConstruct node)
        {
            var name = node switch
            {
                Bucket => "test-bucket-name",
                _ => null
            };

            // Auto-generated names start with $, we skip them.
            if (name != null)
            {
                Tags.Of(node).Add("Name", name.ToLowerInvariant(), new TagProps { Priority = 10 });
            }
        }
    }

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.1004.0

Framework Version

v2.186.0

Node.js Version

v22.5.1

OS

AmazonLinux

Language

.NET

Language Version

net8.0

Other information

I have tried adding @aws-cdk/core:aspectStabilization feature flag, but it changes nothing.

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-s3Related to Amazon S3@aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.p1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions