Package software.amazon.awscdk.cfnpropertymixins
CDK CloudFormation Property Mixins
---
Auto-generated, type-safe CDK Mixins for every CloudFormation resource property.
These allow you to apply L1 properties to any construct (L1, L2, or custom) using the Mixins mechanism from aws-cdk-lib.
Usage
For every CloudFormation resource, this package provides a CfnXxxPropsMixin class.
Apply it using .with() or Mixins.of():
new Bucket(scope, "MyBucket").with(CfnBucketPropsMixin.Builder.create()
.versioningConfiguration(VersioningConfigurationProperty.builder().status("Enabled").build())
.publicAccessBlockConfiguration(PublicAccessBlockConfigurationProperty.builder()
.blockPublicAcls(true)
.blockPublicPolicy(true)
.build())
.build());
Cross-Service References
Deeply nested properties support cross-service references:
Key myKey = new Key(scope, "MyKey");
new Bucket(scope, "EncryptedBucket").with(CfnBucketPropsMixin.Builder.create()
.bucketEncryption(BucketEncryptionProperty.builder()
.serverSideEncryptionConfiguration(List.of(ServerSideEncryptionRuleProperty.builder()
.serverSideEncryptionByDefault(ServerSideEncryptionByDefaultProperty.builder()
.sseAlgorithm("aws:kms")
.kmsMasterKeyId(myKey)
.build())
.build()))
.build())
.build());
Merge Strategies
When a mixin is applied, its properties are merged onto the target resource using a merge strategy. The strategy controls what happens when both the mixin and the existing resource define the same property.
There are two built-in strategies:
PropertyMergeStrategy.combine() (default)
Deep merges nested objects from the mixin into the target. When both the existing and new value for a property are plain objects, their keys are merged recursively — existing keys are preserved and new keys are added. Primitives, arrays, and mismatched types are replaced by the mixin value.
This is useful when you want to add configuration without losing what's already set:
CfnBucket combineBucket = new CfnBucket(scope, "CombineBucket");
combineBucket.getPublicAccessBlockConfiguration() = PublicAccessBlockConfigurationProperty.builder().blockPublicAcls(true).build();
// Adds blockPublicPolicy while preserving the existing blockPublicAcls
combineBucket.with(CfnBucketPropsMixin.Builder.create()
.publicAccessBlockConfiguration(PublicAccessBlockConfigurationProperty.builder().blockPublicPolicy(true).build())
.build());
PropertyMergeStrategy.override()
Replaces existing property values with the mixin values. Each property is copied as-is without inspecting nested objects. Any previous value on the target is discarded.
This is useful when you want to fully replace a configuration:
CfnBucket overrideBucket = new CfnBucket(scope, "OverrideBucket"); overrideBucket.getPublicAccessBlockConfiguration() = PublicAccessBlockConfigurationProperty.builder().blockPublicAcls(true).build(); // Replaces the entire publicAccessBlockConfiguration overrideBucket.with(CfnBucketPropsMixin.Builder.create(CfnBucketMixinProps.builder().publicAccessBlockConfiguration(PublicAccessBlockConfigurationProperty.builder().blockPublicPolicy(true).build()).build()).strategy(PropertyMergeStrategy.override()).build());
Custom Strategies
You can implement IMergeStrategy to define your own merge behavior.
The apply method receives the target object, source object, and an allowlist of property keys:
public class ArrayAppendStrategy implements IMergeStrategy {
public void apply(Object target, Object source, String[] allowedKeys) {
for (Object key : allowedKeys) {
if (key in source) {
if (Array.isArray(target[key])) {
// append to target
target[key] = target[key].concat(source[key]);
} else {
// override
target[key] = source[key];
}
}
}
}
}
CloudFormation Property Mixins for Every Service
This package provides auto-generated property mixins for every CloudFormation resource across all AWS services.
Each service has its own submodule that mirrors the aws-cdk-lib module structure.
Import the mixin for the resource you want to configure from the corresponding service submodule:
import software.amazon.awscdk.cfnpropertymixins.services.s3.CfnBucketPropsMixin; import software.amazon.awscdk.cfnpropertymixins.services.lambda.CfnFunctionPropsMixin; import software.amazon.awscdk.cfnpropertymixins.services.dynamodb.CfnTablePropsMixin; import software.amazon.awscdk.cfnpropertymixins.services.logs.CfnLogGroupPropsMixin; import software.amazon.awscdk.cfnpropertymixins.services.cloudfront.CfnDistributionPropsMixin; import software.amazon.awscdk.cfnpropertymixins.services.rds.CfnDBInstancePropsMixin;
The naming convention follows a consistent pattern: for a CloudFormation resource AWS::S3::Bucket, the mixin class is CfnBucketPropsMixin and lives in the aws-s3 submodule.
The mixin props interface is named CfnBucketMixinProps and all properties are optional, so you only need to specify the ones you want to set.
Property mixins work with any construct that has the target resource as its default child. This means you can apply them to L1 constructs, L2 constructs, and custom constructs alike:
// L1 construct
// L1 construct
new CfnBucket(scope, "L1Bucket").with(CfnBucketPropsMixin.Builder.create().versioningConfiguration(VersioningConfigurationProperty.builder().status("Enabled").build()).build());
// L2 construct — the mixin finds the CfnBucket default child
// L2 construct — the mixin finds the CfnBucket default child
new Bucket(scope, "L2Bucket").with(CfnBucketPropsMixin.Builder.create().versioningConfiguration(VersioningConfigurationProperty.builder().status("Enabled").build()).build());
-
ClassDescriptionOptions for applying CfnProperty mixins.A builder for
CfnPropertyMixinOptionsAn implementation forCfnPropertyMixinOptions