aws-cdk: Adding an aspect to Bucket with S3 notifications leads to an error
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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (13 by maintainers)
Commits related to this issue
- fix: customer aspect cannot add Tags if a BucketNotifications construct is present (#33979) The title refers to a specific case in which we discovered this, but the problem was more general. Now tha... — committed to guessi/aws-cdk by rix0rrr 2 years ago
- fix: customer aspect cannot add Tags if a BucketNotifications construct is present (#33979) The title refers to a specific case in which we discovered this, but the problem was more general. Now tha... — committed to shikha372/aws-cdk by rix0rrr 2 years ago
Found it! Thanks for reporting, and sorry for misunderstanding initially: https://github.com/aws/aws-cdk/pull/33979