Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,11 @@ export class DeliveryStream extends DeliveryStreamBase {
private _role?: iam.IRole;

public get grantPrincipal(): iam.IPrincipal {
if (this._role) {
return this._role;
}
// backwards compatibility
return new iam.Role(this, 'Service Role', {
// backwards compatibility - create role only once
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment backwards compatibility doesn't fully explain the purpose of this change. It's not just for backwards compatibility but also to fix a bug where multiple calls to grantPrincipal would create multiple roles with the same name. Improve the comment to better explain the purpose. Maybe something like:
Create the role only once to ensure multiple calls to grantPrincipal return the same role instance, while maintaining backwards compatibility

this._role = this._role ?? new iam.Role(this, 'Service Role', {
assumedBy: new iam.ServicePrincipal('firehose.amazonaws.com'),
});
return this._role;
}

constructor(scope: Construct, id: string, props: DeliveryStreamProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,15 @@ describe('delivery stream', () => {
expect(deliveryStream.grantPrincipal).toBeInstanceOf(iam.Role);
});

test('multiple calls to grantPrincipal should return the same instance of IAM role', () => {
const deliveryStream = new firehose.DeliveryStream(stack, 'Delivery Stream Multiple', {
destination: mockS3Destination,
});
const principal = deliveryStream.grantPrincipal;
expect(() => deliveryStream.grantPrincipal).not.toThrow();
expect(deliveryStream.grantPrincipal).toBe(principal);
});

describe('metric methods provide a Metric with configured and attached properties', () => {
let deliveryStream: firehose.DeliveryStream;

Expand Down
Loading