Class Key
- All Implemented Interfaces:
IConstruct
,IDependable
,IResource
,IKey
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
Example:
import software.amazon.awscdk.services.kms.*; Key encryptionKey = Key.Builder.create(this, "Key") .enableKeyRotation(true) .build(); Table table = Table.Builder.create(this, "MyTable") .partitionKey(Attribute.builder().name("id").type(AttributeType.STRING).build()) .encryption(TableEncryption.CUSTOMER_MANAGED) .encryptionKey(encryptionKey) .build();
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.core.IConstruct
IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.kms.IKey
IKey.Jsii$Default, IKey.Jsii$Proxy
Nested classes/interfaces inherited from interface software.amazon.awscdk.core.IResource
IResource.Jsii$Default
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionDefines a new alias for the key.addToResourcePolicy
(PolicyStatement statement) Adds a statement to the KMS key resource policy.addToResourcePolicy
(PolicyStatement statement, Boolean allowNoOp) Adds a statement to the KMS key resource policy.static IKey
fromCfnKey
(CfnKey cfnKey) static IKey
fromKeyArn
(software.constructs.Construct scope, String id, String keyArn) Import an externally defined KMS Key using its ARN.static IKey
fromLookup
(software.constructs.Construct scope, String id, KeyLookupOptions options) Import an existing Key by querying the AWS environment this stack is deployed to.The ARN of the key.getKeyId()
The ID of the key (the part that looks something like: 1234abcd-12ab-34cd-56ef-1234567890ab).protected PolicyDocument
Optional policy document that represents the resource policy of this key.protected Boolean
Optional property to control trusting account identities.grant
(IGrantable grantee, @NotNull String... actions) Grant the indicated permissions on this key to the given principal.grantAdmin
(IGrantable grantee) Grant admins permissions using this key to the given principal.grantDecrypt
(IGrantable grantee) Grant decryption permissions using this key to the given principal.grantEncrypt
(IGrantable grantee) Grant encryption permissions using this key to the given principal.grantEncryptDecrypt
(IGrantable grantee) Grant encryption and decryption permissions using this key to the given principal.validate()
Validate the current construct.Methods inherited from class software.amazon.awscdk.core.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isResource
Methods inherited from class software.amazon.awscdk.core.Construct
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesize
Methods inherited from class software.constructs.Construct
toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.awscdk.core.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.core.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
Key
protected Key(software.amazon.jsii.JsiiObjectRef objRef) -
Key
protected Key(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
Key
@Stability(Stable) public Key(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable KeyProps props) - Parameters:
scope
- This parameter is required.id
- This parameter is required.props
-
-
Key
- Parameters:
scope
- This parameter is required.id
- This parameter is required.
-
-
Method Details
-
fromCfnKey
Create a mutableIKey
based on a low-levelCfnKey
.This is most useful when combined with the cloudformation-include module. This method is different than
fromKeyArn()
because theIKey
returned from this method is mutable; meaning, calling any mutating methods on it, like {@link IKey.addToResourcePolicy()}, will actually be reflected in the resulting template, as opposed to the object returned fromfromKeyArn()
, on which calling those methods would have no effect.- Parameters:
cfnKey
- This parameter is required.
-
fromKeyArn
@Stability(Stable) @NotNull public static IKey fromKeyArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String keyArn) Import an externally defined KMS Key using its ARN.- Parameters:
scope
- the construct that will "own" the imported key. This parameter is required.id
- the id of the imported key in the construct tree. This parameter is required.keyArn
- the ARN of an existing KMS key. This parameter is required.
-
fromLookup
@Stability(Stable) @NotNull public static IKey fromLookup(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull KeyLookupOptions options) Import an existing Key by querying the AWS environment this stack is deployed to.This function only needs to be used to use Keys not defined in your CDK application. If you are looking to share a Key between stacks, you can pass the
Key
object between stacks and use it as normal. In addition, it's not necessary to use this method if an interface accepts anIKey
. In this case,Alias.fromAliasName()
can be used which returns an alias that extendsIKey
.Calling this method will lead to a lookup when the CDK CLI is executed. You can therefore not use any values that will only be available at CloudFormation execution time (i.e., Tokens).
The Key information will be cached in
cdk.context.json
and the same Key will be used on future runs. To refresh the lookup, you will have to evict the value from the cache using thecdk context
command. See https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information.- Parameters:
scope
- This parameter is required.id
- This parameter is required.options
- This parameter is required.
-
addAlias
Defines a new alias for the key. -
addToResourcePolicy
@Stability(Stable) @NotNull public AddToResourcePolicyResult addToResourcePolicy(@NotNull PolicyStatement statement, @Nullable Boolean allowNoOp) Adds a statement to the KMS key resource policy.- Specified by:
addToResourcePolicy
in interfaceIKey
- Parameters:
statement
- The policy statement to add. This parameter is required.allowNoOp
- If this is set tofalse
and there is no policy defined (i.e. external key), the operation will fail. Otherwise, it will no-op.
-
addToResourcePolicy
@Stability(Stable) @NotNull public AddToResourcePolicyResult addToResourcePolicy(@NotNull PolicyStatement statement) Adds a statement to the KMS key resource policy.- Specified by:
addToResourcePolicy
in interfaceIKey
- Parameters:
statement
- The policy statement to add. This parameter is required.
-
grant
@Stability(Stable) @NotNull public Grant grant(@NotNull IGrantable grantee, @NotNull @NotNull String... actions) Grant the indicated permissions on this key to the given principal.This modifies both the principal's policy as well as the resource policy, since the default CloudFormation setup for KMS keys is that the policy must not be empty and so default grants won't work.
-
grantAdmin
Grant admins permissions using this key to the given principal.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).
- Parameters:
grantee
- This parameter is required.
-
grantDecrypt
Grant decryption permissions using this key to the given principal.- Specified by:
grantDecrypt
in interfaceIKey
- Parameters:
grantee
- This parameter is required.
-
grantEncrypt
Grant encryption permissions using this key to the given principal.- Specified by:
grantEncrypt
in interfaceIKey
- Parameters:
grantee
- This parameter is required.
-
grantEncryptDecrypt
Grant encryption and decryption permissions using this key to the given principal.- Specified by:
grantEncryptDecrypt
in interfaceIKey
- Parameters:
grantee
- This parameter is required.
-
validate
Validate the current construct.This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.
-
getKeyArn
The ARN of the key. -
getKeyId
The ID of the key (the part that looks something like: 1234abcd-12ab-34cd-56ef-1234567890ab). -
getTrustAccountIdentities
Optional property to control trusting account identities.If specified, grants will default identity policies instead of to both resource and identity policies. This matches the default behavior when creating KMS keys via the API or console.
-
getPolicy
Optional policy document that represents the resource policy of this key.If specified, addToResourcePolicy can be used to edit this policy. Otherwise this method will no-op.
-