Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/aws-cdk-lib/aws-kms/lib/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ abstract class AliasBase extends Resource implements IAlias {
}

public get keyRef(): KeyReference {
return this.aliasTargetKey.keyRef;
// Not actually referering to the key: `IKeyRef` here is being used as a
// hypothetical `IKeyLikeRef`, and we need to return the Alias values using
// the Key interface.
return {
keyArn: this.aliasArn,
keyId: this.keyId,
};
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/aws-kms/lib/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import * as cxapi from '../../cx-api';

/**
* 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.
*/
export interface IKey extends IResource, IKeyRef {
/**
Expand Down
13 changes: 13 additions & 0 deletions packages/aws-cdk-lib/aws-kms/test/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,19 @@ test('aliasArn should be a valid ARN', () => {
}, stack));
});

test('Alias keyRef should reference the Alias, not the underlying key', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'Test');
const key = new Key(stack, 'Key');

// WHEN
const alias = key.addAlias('alias/foo');

// THEN
expect(alias.keyRef.keyArn).toEqual(alias.aliasArn);
});

class AliasOutputsConstruct extends Construct {
constructor(scope: Construct, id: string, key: IKey) {
super(scope, id);
Expand Down
Loading