Class Key.Builder

java.lang.Object
software.amazon.awscdk.services.kms.Key.Builder
All Implemented Interfaces:
software.amazon.jsii.Builder<Key>
Enclosing class:
Key

@Stability(Stable) public static final class Key.Builder extends Object implements software.amazon.jsii.Builder<Key>
A fluent builder for Key.
  • Method Details

    • create

      @Stability(Stable) public static Key.Builder create(software.constructs.Construct scope, String id)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      Returns:
      a new instance of Key.Builder.
    • admins

      @Stability(Stable) public Key.Builder admins(List<? extends IPrincipal> admins)
      A list of principals to add as key administrators to the key policy.

      Key administrators have permissions to manage the key (e.g., change permissions, revoke), but do not have permissions to use the key in cryptographic operations (e.g., encrypt, decrypt).

      These principals will be added to the default key policy (if none specified), or to the specified policy (if provided).

      Default: []

      Parameters:
      admins - A list of principals to add as key administrators to the key policy. This parameter is required.
      Returns:
      this
    • alias

      @Stability(Stable) public Key.Builder alias(String alias)
      Initial alias to add to the key.

      More aliases can be added later by calling addAlias.

      Default: - No alias is added for the key.

      Parameters:
      alias - Initial alias to add to the key. This parameter is required.
      Returns:
      this
    • description

      @Stability(Stable) public Key.Builder description(String description)
      A description of the key.

      Use a description that helps your users decide whether the key is appropriate for a particular task.

      Default: - No description.

      Parameters:
      description - A description of the key. This parameter is required.
      Returns:
      this
    • enabled

      @Stability(Stable) public Key.Builder enabled(Boolean enabled)
      Indicates whether the key is available for use.

      Default: - Key is enabled.

      Parameters:
      enabled - Indicates whether the key is available for use. This parameter is required.
      Returns:
      this
    • enableKeyRotation

      @Stability(Stable) public Key.Builder enableKeyRotation(Boolean enableKeyRotation)
      Indicates whether AWS KMS rotates the key.

      Default: false

      Parameters:
      enableKeyRotation - Indicates whether AWS KMS rotates the key. This parameter is required.
      Returns:
      this
    • keySpec

      @Stability(Stable) public Key.Builder keySpec(KeySpec keySpec)
      The cryptographic configuration of the key. The valid value depends on usage of the key.

      IMPORTANT: If you change this property of an existing key, the existing key is scheduled for deletion and a new key is created with the specified value.

      Default: KeySpec.SYMMETRIC_DEFAULT

      Parameters:
      keySpec - The cryptographic configuration of the key. The valid value depends on usage of the key. This parameter is required.
      Returns:
      this
    • keyUsage

      @Stability(Stable) public Key.Builder keyUsage(KeyUsage keyUsage)
      The cryptographic operations for which the key can be used.

      IMPORTANT: If you change this property of an existing key, the existing key is scheduled for deletion and a new key is created with the specified value.

      Default: KeyUsage.ENCRYPT_DECRYPT

      Parameters:
      keyUsage - The cryptographic operations for which the key can be used. This parameter is required.
      Returns:
      this
    • multiRegion

      @Stability(Stable) public Key.Builder multiRegion(Boolean multiRegion)
      Creates a multi-Region primary key that you can replicate in other AWS Regions.

      You can't change the multiRegion value after the KMS key is created.

      IMPORTANT: If you change the value of the multiRegion property on an existing KMS key, the update request fails, regardless of the value of the UpdateReplacePolicy attribute. This prevents you from accidentally deleting a KMS key by changing an immutable property value.

      Default: false

      Parameters:
      multiRegion - Creates a multi-Region primary key that you can replicate in other AWS Regions. This parameter is required.
      Returns:
      this
      See Also:
    • pendingWindow

      @Stability(Stable) public Key.Builder pendingWindow(Duration pendingWindow)
      Specifies the number of days in the waiting period before AWS KMS deletes a CMK that has been removed from a CloudFormation stack.

      When you remove a customer master key (CMK) from a CloudFormation stack, AWS KMS schedules the CMK for deletion and starts the mandatory waiting period. The PendingWindowInDays property determines the length of waiting period. During the waiting period, the key state of CMK is Pending Deletion, which prevents the CMK from being used in cryptographic operations. When the waiting period expires, AWS KMS permanently deletes the CMK.

      Enter a value between 7 and 30 days.

      Default: - 30 days

      Parameters:
      pendingWindow - Specifies the number of days in the waiting period before AWS KMS deletes a CMK that has been removed from a CloudFormation stack. This parameter is required.
      Returns:
      this
      See Also:
    • policy

      @Stability(Stable) public Key.Builder policy(PolicyDocument policy)
      Custom policy document to attach to the KMS key.

      NOTE - If the @aws-cdk/aws-kms:defaultKeyPolicies feature flag is set (the default for new projects), this policy will override the default key policy and become the only key policy for the key. If the feature flag is not set, this policy will be appended to the default key policy.

      Default: - A policy document with permissions for the account root to administer the key will be created.

      Parameters:
      policy - Custom policy document to attach to the KMS key. This parameter is required.
      Returns:
      this
    • removalPolicy

      @Stability(Stable) public Key.Builder removalPolicy(RemovalPolicy removalPolicy)
      Whether the encryption key should be retained when it is removed from the Stack.

      This is useful when one wants to retain access to data that was encrypted with a key that is being retired.

      Default: RemovalPolicy.Retain

      Parameters:
      removalPolicy - Whether the encryption key should be retained when it is removed from the Stack. This parameter is required.
      Returns:
      this
    • rotationPeriod

      @Stability(Stable) public Key.Builder rotationPeriod(Duration rotationPeriod)
      The period between each automatic rotation.

      Default: - set by CFN to 365 days.

      Parameters:
      rotationPeriod - The period between each automatic rotation. This parameter is required.
      Returns:
      this
    • build

      @Stability(Stable) public Key build()
      Specified by:
      build in interface software.amazon.jsii.Builder<Key>
      Returns:
      a newly built instance of Key.