Skip to content

Commit

Permalink
chore(logs): Adding a public method to access the physical name of th…
Browse files Browse the repository at this point in the history
…e log group (#14947)

This PR adds a public method `logGroupPhysicalName()` to access the physical name of a log group which is a private property of the `Resource` class.

This change is needed to enable using KMS keys with log groups for use with ECS exec.
Related: #13618

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
upparekh authored Jun 2, 2021
1 parent a66fe88 commit 3716eed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-logs/lib/log-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export interface ILogGroup extends IResource {
* Give the indicated permissions on this log group and all streams
*/
grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant;

/**
* Public method to get the physical name of this log group
*/
logGroupPhysicalName(): string;
}

/**
Expand Down Expand Up @@ -173,6 +178,14 @@ abstract class LogGroupBase extends Resource implements ILogGroup {
scope: this,
});
}

/**
* Public method to get the physical name of this log group
* @returns Physical name of log group
*/
public logGroupPhysicalName(): string {
return this.physicalName;
}
}

/**
Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-logs/test/test.loggroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,24 @@ export = {

test.done();
},

'correctly returns physical name of the log group'(test: Test) {
// GIVEN
const stack = new Stack();

// WHEN
const logGroup = new LogGroup(stack, 'LogGroup', {
logGroupName: 'my-log-group',
});

// THEN
test.equal(logGroup.logGroupPhysicalName(), 'my-log-group');
expect(stack).to(haveResource('AWS::Logs::LogGroup', {
LogGroupName: 'my-log-group',
}));

test.done();
},
};

function dataDrivenTests(cases: any[][], body: (test: Test, ...args: any[]) => void) {
Expand Down

0 comments on commit 3716eed

Please sign in to comment.