-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(aws-logs-destinations): add Firehose Log Subscription Destination #14918
Changes from 5 commits
8a294c8
95e9ca7
cbd9a16
f34f5bf
9b3d542
6d52cb2
0f33993
e59b712
6baf06f
7aa9ac4
d706e74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './lambda'; | ||
export * from './kinesis'; | ||
export * from './kinesisfirehose'; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||
import * as iam from '@aws-cdk/aws-iam'; | ||||||||||
import * as firehose from '@aws-cdk/aws-kinesisfirehose'; | ||||||||||
import * as logs from '@aws-cdk/aws-logs'; | ||||||||||
import { Stack } from '@aws-cdk/core'; | ||||||||||
|
||||||||||
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main | ||||||||||
// eslint-disable-next-line no-duplicate-imports, import/order | ||||||||||
import { Construct } from '@aws-cdk/core'; | ||||||||||
|
||||||||||
/** | ||||||||||
* Use a Kinesis Firehose as the destination for a log subscription | ||||||||||
*/ | ||||||||||
export class KinesisFirehoseDestination implements logs.ILogSubscriptionDestination { | ||||||||||
constructor(private readonly deliveryStream: firehose.DeliveryStream) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
} | ||||||||||
|
||||||||||
public bind(_scope: Construct, _sourceLogGroup: logs.ILogGroup): logs.LogSubscriptionDestinationConfig { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
const { region } = Stack.of(this.deliveryStream); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
// Following example from https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html#FirehoseExample | ||||||||||
// Create a role to be assumed by CWL that can write to this Firehose. | ||||||||||
const roleId = 'CloudWatchLogsCanPutRecordsIntoKinesisFirehose'; | ||||||||||
const role = this.deliveryStream.node.tryFindChild(roleId) as iam.IRole ?? | ||||||||||
new iam.Role(this.deliveryStream, roleId, { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With your suggested change we would create 2 identical IAM roles that will fail my unit test in https://github.com/aws/aws-cdk/pull/14918/files#diff-4dab4ab34393d725389edf0c2c55b924e6e9c569d86f78b21ad5d36b8f29b076R104 Do we really want to create 2 identical roles in that unit test case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we do. There should be a logical mapping between the actor and the role, which would be violated if we create one role per delivery stream (as that is the resource). The test case can be modified to demonstrate that we re-use the role if there are multiple Firehose subscriptions from the same log group There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This would still create 2 separate roles because So, it looks like Anyway, I will just remove this unit test case for now as it's impossible to test that condition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah because the destination is bound under SubscriptionFilter, not LogGroup. Okay, no problem with having multiple roles then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear, yes we should remove the |
||||||||||
assumedBy: new iam.ServicePrincipal(`logs.${region}.amazonaws.com`), | ||||||||||
}); | ||||||||||
|
||||||||||
this.deliveryStream.grantPutRecords(role); | ||||||||||
|
||||||||||
return { | ||||||||||
arn: this.deliveryStream.deliveryStreamArn, | ||||||||||
role, | ||||||||||
}; | ||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're feeling up for it, it would be great to have these snippets compile in their first iteration. I'm thinking an initial snippet showing how to set up a log group, then each individual destination uses a fixture seeded with a log group to create the destination. Though ellipses are supported, giving a full specification of the destination resource would be ideal. See: CONTRIBUTING#documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will wait for L2