Class CfnKey
- All Implemented Interfaces:
IInspectable,ITaggable,IKeyRef,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
AWS::KMS::Key resource specifies an KMS key in AWS Key Management Service . You can use this resource to create symmetric encryption KMS keys, asymmetric KMS keys for encryption or signing, and symmetric HMAC KMS keys. You can use AWS::KMS::Key to create multi-Region primary keys of all supported types. To replicate a multi-Region key, use the AWS::KMS::ReplicaKey resource.
If you change the value of the
KeySpec,KeyUsage,Origin, orMultiRegionproperties of an existing KMS key, the update request fails, regardless of the value of theUpdateReplacePolicyattribute . This prevents you from accidentally deleting a KMS key by changing any of its immutable property values. > AWS KMS replaced the term customer master key (CMK) with AWS KMS key and KMS key . The concept has not changed. To prevent breaking changes, AWS KMS is keeping some variations of this term.
You can use symmetric encryption KMS keys to encrypt and decrypt small amounts of data, but they are more commonly used to generate data keys and data key pairs. You can also use a symmetric encryption KMS key to encrypt data stored in AWS services that are integrated with AWS KMS . For more information, see Symmetric encryption KMS keys in the AWS Key Management Service Developer Guide .
You can use asymmetric KMS keys to encrypt and decrypt data or sign messages and verify signatures. To create an asymmetric key, you must specify an asymmetric KeySpec value and a KeyUsage value. For details, see Asymmetric keys in AWS KMS in the AWS Key Management Service Developer Guide .
You can use HMAC KMS keys (which are also symmetric keys) to generate and verify hash-based message authentication codes. To create an HMAC key, you must specify an HMAC KeySpec value and a KeyUsage value of GENERATE_VERIFY_MAC . For details, see HMAC keys in AWS KMS in the AWS Key Management Service Developer Guide .
You can also create symmetric encryption, asymmetric, and HMAC multi-Region primary keys. To create a multi-Region primary key, set the MultiRegion property to true . For information about multi-Region keys, see Multi-Region keys in AWS KMS in the AWS Key Management Service Developer Guide .
You cannot use the AWS::KMS::Key resource to specify a KMS key with imported key material or a KMS key in a custom key store .
Regions
AWS KMS CloudFormation resources are available in all Regions in which AWS KMS and AWS CloudFormation are supported. You can use the AWS::KMS::Key resource to create and manage all KMS key types that are supported in a Region.
Example:
import software.amazon.awscdk.services.kms.*;
Key kmsKey = new Key(this, "myKMSKey");
Bucket myBucket = Bucket.Builder.create(this, "mySSEKMSEncryptedBucket")
.encryption(BucketEncryption.KMS)
.encryptionKey(kmsKey)
.objectOwnership(ObjectOwnership.BUCKET_OWNER_ENFORCED)
.build();
Distribution.Builder.create(this, "myDist")
.defaultBehavior(BehaviorOptions.builder()
.origin(S3BucketOrigin.withOriginAccessControl(myBucket))
.build())
.build();
// Add the following to scope down the key policy
Map<String, Object> scopedDownKeyPolicy = Map.of(
"Version", "2012-10-17",
"Statement", List.of(Map.of(
"Effect", "Allow",
"Principal", Map.of(
"AWS", "arn:aws:iam::111122223333:root"),
"Action", "kms:*",
"Resource", "*"), Map.of(
"Effect", "Allow",
"Principal", Map.of(
"Service", "cloudfront.amazonaws.com"),
"Action", List.of("kms:Decrypt", "kms:Encrypt", "kms:GenerateDataKey*"),
"Resource", "*",
"Condition", Map.of(
"StringEquals", Map.of(
"AWS:SourceArn", "arn:aws:cloudfront::111122223333:distribution/<CloudFront distribution ID>")))));
CfnKey cfnKey = ((CfnKey)kmsKey.getNode().getDefaultChild());
cfnKey.getKeyPolicy() = scopedDownKeyPolicy;
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.IInspectable
IInspectable.Jsii$Default, IInspectable.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.services.kms.IKeyRef
IKeyRef.Jsii$Default, IKeyRef.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.ITaggable
ITaggable.Jsii$Default, ITaggable.Jsii$Proxy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe CloudFormation resource type name for this resource class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCfnKey(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedCfnKey(software.amazon.jsii.JsiiObjectRef objRef) CfnKey(software.constructs.Construct scope, String id, CfnKeyProps props) -
Method Summary
Modifier and TypeMethodDescriptionstatic IKeyReffromKeyArn(software.constructs.Construct scope, String id, String arn) Creates a new IKeyRef from an ARN.static IKeyRefCreates a new IKeyRef from a keyId.The Amazon Resource Name (ARN) of the KMS key, such asarn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab.The key ID of the KMS key, such as1234abcd-12ab-34cd-56ef-1234567890ab.Skips ("bypasses") the key policy lockout safety check.A description of the KMS key.Specifies whether the KMS key is enabled.Enables automatic rotation of the key material for the specified KMS key.The key policy to attach to the KMS key.A reference to a Key resource.Specifies the type of KMS key to create.Determines the cryptographic operations for which you can use the KMS key.Creates a multi-Region primary key that you can replicate in other AWS Regions .The source of the key material for the KMS key.Specifies the number of days in the waiting period before AWS KMS deletes a KMS key that has been removed from a CloudFormation stack.Specifies a custom period of time between each rotation date.getTags()Tag Manager which manages the tags for this resource.Assigns one or more tags to the replica key.voidinspect(TreeInspector inspector) Examines the CloudFormation resource and discloses attributes.renderProperties(Map<String, Object> props) voidSkips ("bypasses") the key policy lockout safety check.voidSkips ("bypasses") the key policy lockout safety check.voidsetDescription(String value) A description of the KMS key.voidsetEnabled(Boolean value) Specifies whether the KMS key is enabled.voidsetEnabled(IResolvable value) Specifies whether the KMS key is enabled.voidsetEnableKeyRotation(Boolean value) Enables automatic rotation of the key material for the specified KMS key.voidsetEnableKeyRotation(IResolvable value) Enables automatic rotation of the key material for the specified KMS key.voidsetKeyPolicy(Object value) The key policy to attach to the KMS key.voidsetKeySpec(String value) Specifies the type of KMS key to create.voidsetKeyUsage(String value) Determines the cryptographic operations for which you can use the KMS key.voidsetMultiRegion(Boolean value) Creates a multi-Region primary key that you can replicate in other AWS Regions .voidsetMultiRegion(IResolvable value) Creates a multi-Region primary key that you can replicate in other AWS Regions .voidThe source of the key material for the KMS key.voidsetPendingWindowInDays(Number value) Specifies the number of days in the waiting period before AWS KMS deletes a KMS key that has been removed from a CloudFormation stack.voidsetRotationPeriodInDays(Number value) Specifies a custom period of time between each rotation date.voidsetTagsRaw(List<CfnTag> value) Assigns one or more tags to the replica key.Methods inherited from class software.amazon.awscdk.CfnResource
addDeletionOverride, addDependency, addDependsOn, addMetadata, addOverride, addPropertyDeletionOverride, addPropertyOverride, applyRemovalPolicy, applyRemovalPolicy, applyRemovalPolicy, getAtt, getAtt, getCfnOptions, getCfnResourceType, getMetadata, getUpdatedProperites, getUpdatedProperties, isCfnResource, obtainDependencies, obtainResourceDependencies, removeDependency, replaceDependency, shouldSynthesize, toString, validatePropertiesMethods inherited from class software.amazon.awscdk.CfnRefElement
getRefMethods inherited from class software.amazon.awscdk.CfnElement
getCreationStack, getLogicalId, getStack, isCfnElement, overrideLogicalIdMethods inherited from class software.constructs.Construct
getNode, isConstructMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.constructs.IConstruct
getNodeMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
CFN_RESOURCE_TYPE_NAME
The CloudFormation resource type name for this resource class.
-
-
Constructor Details
-
CfnKey
protected CfnKey(software.amazon.jsii.JsiiObjectRef objRef) -
CfnKey
protected CfnKey(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
CfnKey
@Stability(Stable) public CfnKey(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable CfnKeyProps props) - Parameters:
scope- Scope in which this resource is defined. This parameter is required.id- Construct identifier for this resource (unique in its scope). This parameter is required.props- Resource properties.
-
CfnKey
- Parameters:
scope- Scope in which this resource is defined. This parameter is required.id- Construct identifier for this resource (unique in its scope). This parameter is required.
-
-
Method Details
-
fromKeyArn
@Stability(Stable) @NotNull public static IKeyRef fromKeyArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String arn) Creates a new IKeyRef from an ARN.- Parameters:
scope- This parameter is required.id- This parameter is required.arn- This parameter is required.
-
fromKeyId
@Stability(Stable) @NotNull public static IKeyRef fromKeyId(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String keyId) Creates a new IKeyRef from a keyId.- Parameters:
scope- This parameter is required.id- This parameter is required.keyId- This parameter is required.
-
inspect
Examines the CloudFormation resource and discloses attributes.- Specified by:
inspectin interfaceIInspectable- Parameters:
inspector- tree inspector to collect and process attributes. This parameter is required.
-
renderProperties
@Stability(Stable) @NotNull protected Map<String,Object> renderProperties(@NotNull Map<String, Object> props) - Overrides:
renderPropertiesin classCfnResource- Parameters:
props- This parameter is required.
-
getAttrArn
The Amazon Resource Name (ARN) of the KMS key, such asarn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab.For information about the key ARN of a KMS key, see Key ARN in the AWS Key Management Service Developer Guide .
-
getAttrKeyId
The key ID of the KMS key, such as1234abcd-12ab-34cd-56ef-1234567890ab.For information about the key ID of a KMS key, see Key ID in the AWS Key Management Service Developer Guide .
-
getCfnProperties
- Overrides:
getCfnPropertiesin classCfnResource
-
getKeyRef
A reference to a Key resource. -
getTags
Tag Manager which manages the tags for this resource. -
getBypassPolicyLockoutSafetyCheck
Skips ("bypasses") the key policy lockout safety check.The default value is false.
Returns union: either
BooleanorIResolvable -
setBypassPolicyLockoutSafetyCheck
Skips ("bypasses") the key policy lockout safety check.The default value is false.
-
setBypassPolicyLockoutSafetyCheck
Skips ("bypasses") the key policy lockout safety check.The default value is false.
-
getDescription
A description of the KMS key. -
setDescription
A description of the KMS key. -
getEnabled
Specifies whether the KMS key is enabled.Disabled KMS keys cannot be used in cryptographic operations.
Returns union: either
BooleanorIResolvable -
setEnabled
Specifies whether the KMS key is enabled.Disabled KMS keys cannot be used in cryptographic operations.
-
setEnabled
Specifies whether the KMS key is enabled.Disabled KMS keys cannot be used in cryptographic operations.
-
getEnableKeyRotation
Enables automatic rotation of the key material for the specified KMS key.Returns union: either
BooleanorIResolvable -
setEnableKeyRotation
Enables automatic rotation of the key material for the specified KMS key. -
setEnableKeyRotation
Enables automatic rotation of the key material for the specified KMS key. -
getKeyPolicy
The key policy to attach to the KMS key. -
setKeyPolicy
The key policy to attach to the KMS key. -
getKeySpec
Specifies the type of KMS key to create. -
setKeySpec
Specifies the type of KMS key to create. -
getKeyUsage
Determines the cryptographic operations for which you can use the KMS key. The default value isENCRYPT_DECRYPT. This property is required for asymmetric KMS keys and HMAC KMS keys. You can't change theKeyUsagevalue after the KMS key is created. -
setKeyUsage
Determines the cryptographic operations for which you can use the KMS key. The default value isENCRYPT_DECRYPT. This property is required for asymmetric KMS keys and HMAC KMS keys. You can't change theKeyUsagevalue after the KMS key is created. -
getMultiRegion
Creates a multi-Region primary key that you can replicate in other AWS Regions .Returns union: either
BooleanorIResolvable -
setMultiRegion
Creates a multi-Region primary key that you can replicate in other AWS Regions . -
setMultiRegion
Creates a multi-Region primary key that you can replicate in other AWS Regions . -
getOrigin
The source of the key material for the KMS key. -
setOrigin
The source of the key material for the KMS key. -
getPendingWindowInDays
Specifies the number of days in the waiting period before AWS KMS deletes a KMS key that has been removed from a CloudFormation stack. -
setPendingWindowInDays
Specifies the number of days in the waiting period before AWS KMS deletes a KMS key that has been removed from a CloudFormation stack. -
getRotationPeriodInDays
Specifies a custom period of time between each rotation date. -
setRotationPeriodInDays
Specifies a custom period of time between each rotation date. -
getTagsRaw
Assigns one or more tags to the replica key. -
setTagsRaw
Assigns one or more tags to the replica key.
-