Skip to content
v2.273.0

Mixin Class ​

Abstract base class for mixins that provides default implementations.

Example ​

ts
class MyEncryptionAtRest extends Mixin {
  constructor(props: MyEncryptionAtRestProps = {}) {
    super();
    // Validate Mixin props at construction time
    if (props.bucketKey && props.algorithm === 'aws:kms:dsse') {
      throw new Error("Cannot use S3 Bucket Key and DSSE together");
    }
  }

  supports(construct: any): construct is s3.CfnBucket {
    return s3.CfnBucket.isCfnBucket(construct);
  }

  applyTo(target: s3.CfnBucket): s3.CfnBucket {
    // Validate pre-conditions on the target, throw if error is unrecoverable
    if (!target.bucketEncryption) {
      throw new Error("Bucket encryption not configured");
    }

    // Validate properties are met after app execution
    target.node.addValidation({
      validate: () => isKmsEncrypted(target)
        ? ['This bucket must use aws:kms encryption.']
        : []
    });

    target.bucketEncryption = {
      serverSideEncryptionConfiguration: [{
        bucketKeyEnabled: true,
        serverSideEncryptionByDefault: {
          sseAlgorithm: "aws:kms"
        }
      }]
    };
    return target;
  }
}

Initializer ​

ts
new Mixin()
python
Mixin()
java
new Mixin()
csharp
new Mixin()
go
NewMixin()

Methods ​

applyTo(construct: IConstruct): voiddef apply_to(self, construct: IConstruct) -> Nonepublic void applyTo(IConstruct construct)public void ApplyTo(IConstruct construct)func ApplyTo(Construct IConstruct)#
Applies the mixin functionality to the target construct.
isMixin(x: any): boolean@staticmethod def is_mixin(x: Any) -> boolpublic static Boolean isMixin(Object x)public static bool IsMixin(object x)func IsMixin(X interface{}) *boolstatic#
Checks if `x` is a Mixin.
1 parameter · returns

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Mixin.

supports(_construct: IConstruct): booleandef supports(self, _construct: IConstruct) -> boolpublic Boolean supports(IConstruct _construct)public bool Supports(IConstruct _construct)func Supports(_construct IConstruct) *bool#
Determines whether this mixin can be applied to the given construct.