Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions packages/@aws-cdk/mixins-preview/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -6,111 +6,3 @@ Copyright 2018-2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.
The AWS CDK includes the following third-party software/licensing:

----------------

** minimatch - https://www.npmjs.com/package/minimatch

Blue Oak Model License

Version 1.0.0

Purpose

This license gives everyone as much permission to work with
this software as possible, while protecting contributors
from liability.

Acceptance

In order to receive this license, you must agree to its
rules. The rules of this license are both obligations
under that agreement and conditions to your license.
You must not do anything with this software that triggers
a rule that you cannot or will not follow.

Copyright

Each contributor licenses you to do everything with this
software that would otherwise infringe that contributor's
copyright in it.

Notices

You must ensure that everyone who gets a copy of
any part of this software from you, with or without
changes, also gets the text of this license or a link to
https://blueoakcouncil.org/license/1.0.0.

Excuse

If anyone notifies you in writing that you have not
complied with Notices, you can keep your
license by taking all practical steps to comply within 30
days after the notice. If you do not do so, your license
ends immediately.

Patent

Each contributor licenses you to do everything with this
software that would otherwise infringe any patent claims
they can license or become able to license.

Reliability

No contributor can revoke this license.

No Liability

As far as the law allows, this software comes as is,
without any warranty or condition, and no contributor
will be liable to anyone for any damages related to this
software or this license, under any kind of legal claim.

----------------

** brace-expansion - https://www.npmjs.com/package/brace-expansion
Copyright Julian Gruber <julian@juliangruber.com>
TypeScript port Copyright Isaac Z. Schlueter <i@izs.me>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

----------------

** balanced-match - https://www.npmjs.com/package/balanced-match
Original code Copyright Julian Gruber <julian@juliangruber.com>
Port to TypeScript Copyright Isaac Z. Schlueter <i@izs.me>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

----------------
127 changes: 31 additions & 96 deletions packages/@aws-cdk/mixins-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,92 +15,35 @@

<!--END STABILITY BANNER-->

> **Note**: The core Mixins mechanism (`Mixins`, `Mixin`, `IMixin`, `MixinApplicator`, `ConstructSelector`) is now available in `constructs` and `aws-cdk-lib/core`. Please update your imports.
> This package continues to provide additional preview features until they move to their final destinations.

This package provides two main features:

1. **Mixins** - Composable abstractions for adding functionality to constructs
2. **EventBridge Event Patterns** - Type-safe event patterns for AWS resources

---

## CDK Mixins

CDK Mixins provide a new, advanced way to add functionality through composable abstractions.
Unlike traditional L2 constructs that bundle all features together, Mixins allow you to pick and choose exactly the capabilities you need for constructs.

### Key Benefits
## Key Benefits

CDK Mixins offer a well-defined way to build self-contained constructs features.
Mixins are applied during or after construct construction.

* **Universal Compatibility**: Apply the same abstractions to L1 constructs, L2 constructs, or custom constructs
* **Composable Design**: Mix and match features without being locked into specific implementations
* **Composable Design**: Mix and match features without being locked into specific implementations
* **Cross-Service Abstractions**: Use common patterns like encryption across different AWS services
* **Escape Hatch Freedom**: Customize resources in a safe, typed way while keeping the abstractions you want

### Basic Usage

Mixins use `Mixins.of()` as the fundamental API for applying abstractions to constructs:

```typescript
// Base form: apply mixins to any construct
const bucket = new s3.CfnBucket(scope, "MyBucket");
Mixins.of(bucket)
.apply(new EncryptionAtRest())
.apply(new AutoDeleteObjects());
```

#### Fluent Syntax with `.with()`

For convenience, you can use the `.with()` method for a more fluent syntax:

```typescript
import '@aws-cdk/mixins-preview/with';

const bucket = new s3.CfnBucket(scope, "MyBucket")
.with(new BucketVersioning())
.with(new AutoDeleteObjects());
```

The `.with()` method is available after importing `@aws-cdk/mixins-preview/with`, which augments all constructs with this method. It provides the same functionality as `Mixins.of().apply()` but with a more chainable API.

> **Note**: The `.with()` fluent syntax is only available in JavaScript and TypeScript. Other jsii languages (Python, Java, C#, and Go) should use the `Mixins.of(...).requireAll()` syntax instead. The import requirement is temporary during the preview phase. Once the API is stable, the `.with()` method will be available by default on all constructs and in all languages.

### Creating Custom Mixins

Mixins are simple classes that implement the `IMixin` interface (usually by extending the abstract `Mixin` class:
Mixins are an _addition_, _not_ a replacement for construct properties.
By itself, they cannot change optionality of properties or change defaults.

```typescript
// Simple mixin that enables versioning
class CustomVersioningMixin extends Mixin implements IMixin {
supports(construct: any): boolean {
return construct instanceof s3.CfnBucket;
}

applyTo(bucket: any): void {
bucket.versioningConfiguration = {
status: "Enabled"
};
}
}

// Usage
const bucket = new s3.CfnBucket(scope, "MyBucket");
Mixins.of(bucket).apply(new CustomVersioningMixin());
```

### Construct Selection

Mixins operate on construct trees and can be applied selectively:

```typescript
// Apply to all constructs in a scope
Mixins.of(scope).apply(new EncryptionAtRest());
### Usage and documentation

// Apply to specific resource types
Mixins.of(scope, ConstructSelector.resourcesOfType(s3.CfnBucket.CFN_RESOURCE_TYPE_NAME))
.apply(new EncryptionAtRest());

// Apply to constructs matching a path pattern
Mixins.of(scope, ConstructSelector.byPath("**/*-prod-*/**"))
.apply(new ProductionSecurityMixin());
```
See the [documentation for `aws-cdk-lib`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib-readme.html#mixins).

### Built-in Mixins

Expand All @@ -110,41 +53,39 @@ Mixins.of(scope, ConstructSelector.byPath("**/*-prod-*/**"))

```typescript
// Works across different resource types
const bucket = new s3.CfnBucket(scope, "Bucket");
Mixins.of(bucket).apply(new EncryptionAtRest());
const myBucket = new s3.CfnBucket(scope, "Bucket");
Mixins.of(myBucket).apply(new EncryptionAtRest());

const logGroup = new logs.CfnLogGroup(scope, "LogGroup");
Mixins.of(logGroup).apply(new EncryptionAtRest());
const myLogGroup = new logs.CfnLogGroup(scope, "LogGroup");
Mixins.of(myLogGroup).apply(new EncryptionAtRest());
```

#### S3-Specific Mixins

**AutoDeleteObjects**: Configures automatic object deletion for S3 buckets

```typescript
const bucket = new s3.CfnBucket(scope, "Bucket");
Mixins.of(bucket).apply(new AutoDeleteObjects());
const myBucket = new s3.CfnBucket(scope, "Bucket");
Mixins.of(myBucket).apply(new AutoDeleteObjects());
```

**BucketVersioning**: Enables versioning on S3 buckets

```typescript
const bucket = new s3.CfnBucket(scope, "Bucket");
Mixins.of(bucket).apply(new BucketVersioning());
const myBucket = new s3.CfnBucket(scope, "Bucket");
Mixins.of(myBucket).apply(new BucketVersioning());
```

**BucketBlockPublicAccess**: Enables blocking public-access on S3 buckets

```typescript
const bucket = new s3.CfnBucket(scope, "Bucket");
Mixins.of(bucket).apply(new BucketBlockPublicAccess());
const myBucket = new s3.CfnBucket(scope, "Bucket");
Mixins.of(myBucket).apply(new BucketBlockPublicAccess());
```

**BucketPolicyStatementsMixin**: Adds IAM policy statements to a bucket policy

```typescript
declare const bucket: s3.IBucketRef;

const bucketPolicy = new s3.CfnBucketPolicy(scope, "BucketPolicy", {
bucket: bucket,
policyDocument: new iam.PolicyDocument(),
Expand Down Expand Up @@ -178,14 +119,13 @@ Mixins.of(cluster).apply(new ClusterSettings([{
Configures vended logs delivery for supported resources to various destinations:

```typescript
import '@aws-cdk/mixins-preview/with';
import * as cloudfrontMixins from '@aws-cdk/mixins-preview/aws-cloudfront/mixins';

// Create CloudFront distribution
declare const bucket: s3.Bucket;
declare const origin: s3.IBucket;
const distribution = new cloudfront.Distribution(scope, 'Distribution', {
defaultBehavior: {
origin: origins.S3BucketOrigin.withOriginAccessControl(bucket),
origin: origins.S3BucketOrigin.withOriginAccessControl(origin),
},
});

Expand All @@ -212,10 +152,10 @@ import '@aws-cdk/mixins-preview/with';
import * as cloudfrontMixins from '@aws-cdk/mixins-preview/aws-cloudfront/mixins';

// Create CloudFront distribution
declare const bucket: s3.Bucket;
declare const origin: s3.IBucket;
const distribution = new cloudfront.Distribution(scope, 'Distribution', {
defaultBehavior: {
origin: origins.S3BucketOrigin.withOriginAccessControl(bucket),
origin: origins.S3BucketOrigin.withOriginAccessControl(origin),
},
});

Expand Down Expand Up @@ -272,10 +212,10 @@ const sourceStack = new Stack(app, 'source-stack', {
});

// Create CloudFront distribution
declare const bucket: s3.Bucket;
declare const origin: s3.IBucket;
const distribution = new cloudfront.Distribution(sourceStack, 'Distribution', {
defaultBehavior: {
origin: origins.S3BucketOrigin.withOriginAccessControl(bucket),
origin: origins.S3BucketOrigin.withOriginAccessControl(origin),
},
});

Expand All @@ -292,8 +232,7 @@ For every CloudFormation resource, CDK Mixins automatically generates type-safe
```typescript
import '@aws-cdk/mixins-preview/with';


const bucket = new s3.Bucket(scope, "Bucket")
new s3.Bucket(scope, "Bucket")
.with(new CfnBucketPropsMixin({
versioningConfiguration: { status: "Enabled" },
publicAccessBlockConfiguration: {
Expand All @@ -306,8 +245,6 @@ const bucket = new s3.Bucket(scope, "Bucket")
Property mixins support two merge strategies:

```typescript
declare const bucket: s3.CfnBucket;

// MERGE (default): Deep merges properties with existing values
Mixins.of(bucket).apply(new CfnBucketPropsMixin(
{ versioningConfiguration: { status: "Enabled" } },
Expand Down Expand Up @@ -358,8 +295,8 @@ import * as events from 'aws-cdk-lib/aws-events';
import * as targets from 'aws-cdk-lib/aws-events-targets';

// Works with L2 constructs
const bucket = new s3.Bucket(scope, 'Bucket');
const bucketEvents = BucketEvents.fromBucket(bucket);
const myBucket = new s3.Bucket(scope, 'Bucket');
const bucketEvents = BucketEvents.fromBucket(myBucket);
declare const fn: lambda.Function;

new events.Rule(scope, 'Rule', {
Expand Down Expand Up @@ -389,7 +326,6 @@ new events.CfnRule(scope, 'CfnRule', {
```typescript
import { BucketEvents } from '@aws-cdk/mixins-preview/aws-s3/events';

declare const bucket: s3.Bucket;
const bucketEvents = BucketEvents.fromBucket(bucket);

// Bucket name is automatically injected from the bucket reference
Expand All @@ -403,7 +339,6 @@ const pattern = bucketEvents.objectCreatedPattern();
import { BucketEvents } from '@aws-cdk/mixins-preview/aws-s3/events';
import * as events from 'aws-cdk-lib/aws-events';

declare const bucket: s3.Bucket;
const bucketEvents = BucketEvents.fromBucket(bucket);

const pattern = bucketEvents.objectCreatedPattern({
Expand Down
25 changes: 0 additions & 25 deletions packages/@aws-cdk/mixins-preview/lib/core/private/metadata.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/@aws-cdk/mixins-preview/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * as core from './core';
export * as mixins from './mixins';
export * from './services';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mixin } from '../../core';
import { Mixin } from 'aws-cdk-lib/core';
import { CfnCluster } from 'aws-cdk-lib/aws-ecs';
import type { IConstruct } from 'constructs/lib/construct';

Expand Down
Loading
Loading