Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(kms): prefer new aliasArn to keyArn for getting arn of an alias #28197

Merged
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-kms/lib/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ abstract class AliasBase extends Resource implements IAlias {

public abstract readonly aliasTargetKey: IKey;

/**
* The ARN of the alias.
*
* @attribute
* @deprecated use `aliasArn` instead
*/
public get keyArn(): string {
return Stack.of(this).formatArn({
service: 'kms',
Expand All @@ -67,6 +73,15 @@ abstract class AliasBase extends Resource implements IAlias {
});
}

/**
* The ARN of the alias.
*
* @attribute
*/
public get aliasArn(): string {
return this.keyArn;
}
rafaelrcamargo marked this conversation as resolved.
Show resolved Hide resolved

public get keyId(): string {
return this.aliasName;
}
Expand Down
10 changes: 10 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 @@ -357,6 +357,16 @@ test('does not add alias if starts with token', () => {
});
});

test('aliasArn and keyArn from alias should match', () => {
const app = new App();
const stack = new Stack(app, 'Test');
const key = new Key(stack, 'Key');

const alias = new Alias(stack, 'Alias', { targetKey: key, aliasName: 'alias/foo' });

expect(alias.aliasArn).toEqual(alias.keyArn);
});

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