# IKey

A KMS Key, either managed by this CDK app, or imported.

This interface does double duty: it represents an actual KMS keys, but it
also represents things that can behave like KMS keys, like a key alias.

Extends: IKey
Extends: IResource, IKeyRef
Implemented by: Alias, Key

- Source: [`aws-kms/lib/key.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-kms/lib/key.ts#L39)
- Type last changed: v2.224.0 · 13 Nov 2025

## Properties

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `keyArn`: string (required) — The ARN of the key.

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

- `keyRef`: [KeyReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_kms.KeyReference.html) (required) — A reference to a Key resource.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

## Methods

- `addAlias(alias: string): Alias` — Defines a new alias for the key.

- `addToResourcePolicy(statement: PolicyStatement, allowNoOp?: boolean): AddToResourcePolicyResult` — Adds a statement to the KMS key resource policy.

  **Parameters**

  - `statement` — The policy statement to add.
  - `allowNoOp` — 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.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `grant(grantee: IGrantable, ...actions: string[]): Grant` — Grant the indicated permissions on this key to the given principal.

- `grantDecrypt(grantee: IGrantable): Grant` — Grant decryption permissions using this key to the given principal.

- `grantEncrypt(grantee: IGrantable): Grant` — Grant encryption permissions using this key to the given principal.

- `grantEncryptDecrypt(grantee: IGrantable): Grant` — Grant encryption and decryption permissions using this key to the given principal.

- `grantGenerateMac(grantee: IGrantable): Grant` — Grant permissions to generating MACs to the given principal.

- `grantSign(grantee: IGrantable): Grant` — Grant sign permissions using this key to the given principal.

- `grantSignVerify(grantee: IGrantable): Grant` — Grant sign and verify permissions using this key to the given principal.

- `grantVerify(grantee: IGrantable): Grant` — Grant verify permissions using this key to the given principal.

- `grantVerifyMac(grantee: IGrantable): Grant` — Grant permissions to verifying MACs to the given principal.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
