Select your cookie preferences

We use cookies and similar tools to enhance your experience, provide our services, deliver relevant advertising, and make improvements. Approved third parties also use these tools to help us deliver advertising and provide certain site features.

@aws-cdk/aws-kms

The CDK Construct Library for AWS::KMS


AWS icon

AWS

Author Amazon Web Services

Published

Repository github.com

License Apache-2.0

Registry www.npmjs.com


npm install @aws-cdk/aws-kms@1.85.0

Key

Defines a KMS key.

Initializers

import { Key } from '@aws-cdk/aws-kms'
new Key(scope: Construct, id: string, props?: KeyProps)
NameTypeDescription
scopeConstructNo description.
idstringNo description.
propsKeyPropsNo description.
scopeRequired
idRequired
  • Type: string
propsOptional

Methods

NameDescription
toStringReturns a string representation of this construct.
addAliasDefines a new alias for the key.
addToResourcePolicyAdds a statement to the KMS key resource policy.
grantGrant the indicated permissions on this key to the given principal.
grantAdminGrant admins permissions using this key to the given principal.
grantDecryptGrant decryption permissions using this key to the given principal.
grantEncryptGrant encryption permissions using this key to the given principal.
grantEncryptDecryptGrant encryption and decryption permissions using this key to the given principal.
toString
public toString(): string

Returns a string representation of this construct.

addAlias
public addAlias(aliasName: string): Alias

Defines a new alias for the key.

aliasNameRequired
  • Type: string
addToResourcePolicy
public addToResourcePolicy(statement: PolicyStatement, allowNoOp?: boolean): AddToResourcePolicyResult

Adds a statement to the KMS key resource policy.

statementRequired

The policy statement to add.

allowNoOpOptional
  • Type: boolean

If this is set to false and there is no policy defined (i.e. external key), the operation will fail. Otherwise, it will no-op.

grant
public grant(grantee: IGrantable, actions: string): Grant

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.

granteeRequired
actionsRequired
  • Type: string
grantAdmin
public grantAdmin(grantee: IGrantable): Grant

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).

granteeRequired
grantDecrypt
public grantDecrypt(grantee: IGrantable): Grant

Grant decryption permissions using this key to the given principal.

granteeRequired
grantEncrypt
public grantEncrypt(grantee: IGrantable): Grant

Grant encryption permissions using this key to the given principal.

granteeRequired
grantEncryptDecrypt
public grantEncryptDecrypt(grantee: IGrantable): Grant

Grant encryption and decryption permissions using this key to the given principal.

granteeRequired

Static Functions

NameDescription
isConstructReturn whether the given object is a Construct.
fromKeyArnImport an externally defined KMS Key using its ARN.
isConstruct
import { Key } from '@aws-cdk/aws-kms'
Key.isConstruct(x: any)

Return whether the given object is a Construct.

xRequired
  • Type: any
fromKeyArn
import { Key } from '@aws-cdk/aws-kms'
Key.fromKeyArn(scope: Construct, id: string, keyArn: string)

Import an externally defined KMS Key using its ARN.

scopeRequired

the construct that will "own" the imported key.

idRequired
  • Type: string

the id of the imported key in the construct tree.

keyArnRequired
  • Type: string

the ARN of an existing KMS key.

Properties

NameTypeDescription
nodeConstructNodeThe construct tree node associated with this construct.
envResourceEnvironmentThe environment this resource belongs to.
stackStackThe stack in which this resource is defined.
keyArnstringThe ARN of the key.
keyIdstringThe ID of the key (the part that looks something like: 1234abcd-12ab-34cd-56ef-1234567890ab).
nodeRequired
public readonly node: ConstructNode;

The construct tree node associated with this construct.

envRequired
public readonly env: ResourceEnvironment;

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

stackRequired
public readonly stack: Stack;

The stack in which this resource is defined.

keyArnRequired
public readonly keyArn: string;
  • Type: string

The ARN of the key.

keyIdRequired
public readonly keyId: string;
  • Type: string

The ID of the key (the part that looks something like: 1234abcd-12ab-34cd-56ef-1234567890ab).