CDK Constructs for AWS KMS
Project description
AWS KMS Construct Library
Defines a KMS key:
new EncryptionKey(this, 'MyKey', {
enableKeyRotation: true
});
Add a couple of aliases:
const key = new EncryptionKey(this, 'MyKey');
key.addAlias('alias/foo');
key.addAlias('alias/bar');
Sharing keys between stacks
To use a KMS key in a different stack in the same CDK application, pass the construct to the other stack:
/**
* Stack that defines the key
*/
class KeyStack extends cdk.Stack {
public readonly key: kms.EncryptionKey;
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
this.key = new kms.EncryptionKey(this, 'MyKey', { retain: false });
}
}
interface UseStackProps extends cdk.StackProps {
key: kms.IEncryptionKey; // Use IEncryptionKey here
}
/**
* Stack that uses the key
*/
class UseStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: UseStackProps) {
super(scope, id, props);
// Use the IEncryptionKey object here.
props.key.addAlias('alias/foo');
}
}
const keyStack = new KeyStack(app, 'KeyStack');
new UseStack(app, 'UseStack', { key: keyStack.key });
Importing existing keys
To use a KMS key that is not defined in this CDK app, but is created through other means, use
EncryptionKey.import(parent, name, ref)
:
const myKeyImported = EncryptionKey.import(this, 'MyImportedKey', {
keyArn: 'arn:aws:...'
});
// you can do stuff with this imported key.
key.addAlias('alias/foo');
Note that a call to .addToPolicy(statement)
on myKeyImported
will not have
an affect on the key's policy because it is not owned by your stack. The call
will be a no-op.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aws-cdk.aws-kms-0.28.0.tar.gz
(49.4 kB
view hashes)
Built Distribution
Close
Hashes for aws_cdk.aws_kms-0.28.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdabf44d7875aeeee39d7e50614dfae65cb32c2533bdb6fb2ab1be7283fe9d96 |
|
MD5 | 226e99b14061ba03537eeb8a3439496d |
|
BLAKE2b-256 | 8048ad109d924988eda5264f3d5e4c9a108fa908fca4d2d289e2350e172c2259 |