AWS CDK Mixins: Composable Capabilities That Blur the L1/L2 Boundary
#Infrastructure

AWS CDK Mixins: Composable Capabilities That Blur the L1/L2 Boundary

Infrastructure Reporter
5 min read

AWS shipped CDK Mixins, a way to attach reusable behaviors like security and monitoring onto any construct with a .with() call. The feature targets a long-standing pain point: choosing between day-one access to new AWS resources and the convenience defaults that take weeks or months to arrive.

AWS has rolled out CDK Mixins, a feature in the AWS Cloud Development Kit that lets developers attach reusable capabilities, such as security configuration, monitoring, and compliance policies, onto infrastructure resources regardless of which construct level they started from. The feature is built directly into aws-cdk-lib and reached general availability in March, though the AWS team published its announcement blog post in late May. The mechanism is a chained .with() syntax that composes behaviors onto an existing construct.

Featured image

To understand why Mixins exist, you need to understand the construct hierarchy that has defined CDK since its early releases. The CDK provisions cloud resources by generating CloudFormation templates, and it organizes reusable components into three levels. L1 constructs map one-to-one to CloudFormation resource types and are auto-generated from the CloudFormation resource specification. L2 constructs wrap those primitives with sensible defaults, helper methods, and type safety. L3 constructs, often called patterns, stitch multiple resources into a higher-level unit such as a load-balanced Fargate service.

The trade-off Mixins target

The three-tier model created a recurring friction point around timing. When AWS ships a new feature on a service, the L1 construct picks it up immediately because L1s are regenerated from the CloudFormation specs. The L2 construct, the one most teams actually want because it carries the defaults and convenience methods, lags behind until someone on the CDK team writes the abstraction. That delay can run weeks or months.

Monica Colangelo, head of hyperscaler operations at ReeVo, described the bind concisely. Using an S3 bucket as the example, the L1 CfnBucket supports a brand-new property on day one, while the L2 Bucket with its nice defaults won't support it until the abstraction is written. "So until now, you either used L2 and waited, or dropped to L1 and manually configured everything you were getting for free. Not ideal," she wrote. Mixins change the calculus: you can start from an L1 construct for immediate access to a new property and then chain on the behaviors you need, rather than re-implementing everything the L2 would have given you.

Michael Kaiser, senior software development engineer at AWS, and Momo Kornher, solutions architect at AWS, framed the design goal in terms of decoupling. "By decoupling capabilities from construct implementations, Mixins give you the freedom to compose exactly the infrastructure you need, whether you are using L1 constructs for access to new CloudFormation resources, L2 constructs for convenience, or custom constructs for enterprise requirements," they wrote. The practical result is that the once-firm wall between L1 and L2 becomes porous. You are no longer forced to pick a tier and live with its limitations.

How Mixins differ from Aspects

CDK already had a mechanism for cross-cutting concerns: Aspects. An Aspect applies an operation to every construct within a given scope during synthesis, which makes it a natural fit for enforcing organization-wide rules. The obvious question is why Mixins are needed when Aspects exist, and the answer is that they operate at different points in the lifecycle and at different granularity.

Kaiser and Kornher describe the two as complementary rather than competing. Mixins apply features immediately to specific constructs at the point you declare them. Aspects enforce rules broadly across a scope during the synthesis phase. The pattern they recommend pairs the two: use Mixins to configure resources, then use Aspects to validate that the configuration satisfies your policy. In other words, Mixins are the imperative "do this here" tool, and Aspects remain the declarative "check everything" tool. A team building a compliance baseline might use a Mixin to attach encryption and logging to a bucket, then run an Aspect across the entire stack to confirm no bucket slipped through without those settings.

Deployment considerations

Because Mixins ship inside aws-cdk-lib and reuse the same service imports developers already work with, adoption does not require a new dependency or a separate package. They function across L1, L2, and L3 constructs, so existing stacks can start composing behaviors incrementally rather than through a wholesale rewrite. For teams that have accumulated forked or heavily customized constructs purely to bolt on security and monitoring defaults, Mixins offer a path to retire some of that custom code and express the same intent as composable, reusable units.

The added flexibility carries an obvious cost: another concept in a stack that already asks newcomers to reason about three construct tiers, Aspects, and now composition across all of them. Corey Quinn, chief cloud economist at The Duckbill Group, captured the skeptical view in his newsletter, noting that you can now compose abstractions across all three construct types, "which sounds great until you realize you're writing TypeScript to generate YAML to provision JSON." The jab lands because it points at a real tension. Each layer of abstraction the CDK adds buys expressiveness at the price of indirection, and Mixins are another layer. Teams that value the directness of Terraform or its fork OpenTofu will see this as further evidence that the CDK trades transparency for power.

Whether that trade is worth it depends on how much your team was already fighting the L1/L2 boundary. If you frequently hit the wall of waiting for an L2 to catch up with a new CloudFormation property, Mixins remove a genuine source of friction and let you keep convenience and currency at the same time. The CDK Mixins documentation is available on GitHub for teams evaluating the feature against their own construct usage.

Comments

Loading comments...