-
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8a294c8
feat(aws-logs-destinations): add Firehose Log Subscription Destination
yerzhan7 95e9ca7
Merge remote-tracking branch 'upstream/master'
yerzhan7 cbd9a16
Fix single role scope issue
yerzhan7 f34f5bf
Migrate to L2 DeliveryStream
yerzhan7 9b3d542
Revert whitespace changes in rules.ts
yerzhan7 6d52cb2
Fix integration test and address some comments
yerzhan7 0f33993
Change role scope and remove unit test case
yerzhan7 e59b712
Remove `tryFindChild` and always create role
yerzhan7 6baf06f
Merge remote-tracking branch 'upstream/master'
yerzhan7 7aa9ac4
Merge remote-tracking branch 'upstream/master'
yerzhan7 d706e74
Merge remote-tracking branch 'upstream/master'
yerzhan7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './lambda'; | ||
export * from './kinesis'; | ||
export * from './kinesisfirehose'; |
34 changes: 34 additions & 0 deletions
34
packages/@aws-cdk/aws-logs-destinations/lib/kinesisfirehose.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
import * as firehose from '@aws-cdk/aws-kinesisfirehose'; | ||
import * as logs from '@aws-cdk/aws-logs'; | ||
|
||
// 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.IDeliveryStream) { | ||
} | ||
|
||
public bind(scope: Construct, _sourceLogGroup: logs.ILogGroup): logs.LogSubscriptionDestinationConfig { | ||
const region = this.deliveryStream.env.region; | ||
|
||
// 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 = scope.node.tryFindChild(roleId) as iam.IRole ?? | ||
new iam.Role(scope, roleId, { | ||
assumedBy: new iam.ServicePrincipal(`logs.${region}.amazonaws.com`), | ||
}); | ||
|
||
this.deliveryStream.grantPutRecords(role); | ||
|
||
return { | ||
arn: this.deliveryStream.deliveryStreamArn, | ||
role, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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