I recently stumbled across CDK Aspects on the AWS open source news and updates new letter. There was a link to an example Tag checker that I thought I would try out in C#.
I originally had the class defined as
1 | public class TagAspect : IAspect |
But when I ran CDK synth I got this error
1 | Unhandled exception. System.ArgumentException: Could not convert argument 'DeployLambda.TagAspect' to Jsii (Parameter 'arguments') |
After a bit of Googling I found there is a known issue with an easy fix. You just need to make sure the aspect class inherites from Amazon.Jsii.Runtime.Deputy.DeputyBase
The working code is
1 | public class TagAspect : Amazon.JSII.Runtime.Deputy.DeputyBase, IAspect |
You wire this in to the program.cs
1 | Aspects.Of(app).Add(new TagAspect(new List<string>{"owner"})); |
Which gives this error is we don’t have a owner tag set
1 | [Error at /lambda-pipeline] Missing required tag owner on stack with id lambda-pipeline |