Skip to content

feat(logs): custom Role for Kinesis destination#13553

Merged
mergify[bot] merged 19 commits intoaws:masterfrom
gmeligio:master
Feb 16, 2022
Merged

feat(logs): custom Role for Kinesis destination#13553
mergify[bot] merged 19 commits intoaws:masterfrom
gmeligio:master

Conversation

@gmeligio
Copy link
Copy Markdown
Contributor

@gmeligio gmeligio commented Mar 11, 2021

  • Testing
    • Unit test added.
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated

When creating a logs destination, an optional role can be passed to be assumed when writing logs in the destination.

Closes #7661.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Mar 11, 2021

@github-actions github-actions bot added @aws-cdk/aws-events Related to CloudWatch Events @aws-cdk/aws-logs Related to Amazon CloudWatch Logs labels Mar 11, 2021
@gmeligio
Copy link
Copy Markdown
Contributor Author

I was able to unit test aws-logs but no aws-logs-destinations because the latter has peer-dependencies that are not available with yarn install like @aws-cdk/aws-iam and @aws-cdk/aws-lambda.

Copy link
Copy Markdown
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

It looks like what you're trying to do is preventing the Kinesis destination from creating a Role for you. I'm assuming because your organization does not allow the creation of new Roles by developers.

Right now it's the case that the ILogSubscriptionDestination is responsible for creating the Roles. If you want it to stop doing that, the easiest way is to make a pre-existing Role configurable on all the individual subclasses of ILogSubscriptionDestination, starting with the Kinesis one. Create a new (optional) Props object with a single role?: Role field, and use that one if given instead of creating a new one. This is the pattern used all across the CDK.


The next question might be--does this make sense? Should the Role not be configured by the subscription filter itself instead of its destination?

A case could definitely be made for that. That requires a bigger refactor, where we add the role?: Role argument to SubscriptionFilterOptions, and we need to add some protocol between the SubscriptionFilter and the Destination to indicate whether or not the filter already HAS a role or needs one configured (and even if one already exists, permissions may still need to be added to them!).

You could also take on that, I'm not opposed to it.


In neither case is a change to LogGroup necessary, or does LogGroup implicitly get a Role or something. You are using the LogGroup object to transport a single variable somewhere else -- that doesn't seem necessargy.

logGroup,
destination: new LogsDestinations.LambdaDestination(fn),
filterPattern: FilterPattern.allTerms("ERROR", "MainThread")
roleArn: role.roleArn
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not roleArn though, right?

* @default No role assumed
* @attribute
*/
readonly role?: iam.IRole;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to expose this here.

@rix0rrr rix0rrr removed their assignment Jun 22, 2021
@gmeligio gmeligio marked this pull request as draft September 5, 2021 17:26
@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Oct 24, 2021

@mergify mergify bot dismissed rix0rrr’s stale review October 24, 2021 11:12

Pull request has been modified.

@gmeligio gmeligio marked this pull request as ready for review October 24, 2021 11:18
@gmeligio
Copy link
Copy Markdown
Contributor Author

I was trying to solve this issue, but I don't have this problem in particular in my organization. Thank you for the guidance @rix0rrr .

I studied other packages in the CDK to understand your points.

I decided to go with option one and customize destination subclasses as the pattern used all across the CDK. It seems like it's suitable for the issue use case. Still, maybe I can implement the second option if it's necessary with the role creation protocol between SubscriptionFilter and the Destination.

When adding the role property to destination subclasses, I couldn't find a way to do it for LambdaDestination, and I think it is unnecessary. I customized only the KinesisDestination subclass and moved the tests to aws-logs-destinations. I added a snippet of the feature in the README.md so it can be discovered easily.

@gmeligio gmeligio changed the title feat(aws-logs): allow optional role to write log events in destination feat(aws-logs-destinations): allow optional role to write log events in destination Oct 24, 2021
@gmeligio gmeligio requested a review from rix0rrr December 27, 2021 17:34
@rix0rrr rix0rrr changed the title feat(aws-logs-destinations): allow optional role to write log events in destination feat(logs): custom Role for Kinesis destination Feb 15, 2022
rix0rrr
rix0rrr previously approved these changes Feb 15, 2022
@mergify mergify bot dismissed rix0rrr’s stale review February 15, 2022 13:26

Pull request has been modified.

rix0rrr
rix0rrr previously approved these changes Feb 15, 2022
@mergify mergify bot dismissed rix0rrr’s stale review February 15, 2022 15:02

Pull request has been modified.

@rix0rrr rix0rrr added the pr-linter/exempt-readme The PR linter will not require README changes label Feb 15, 2022
rix0rrr
rix0rrr previously approved these changes Feb 15, 2022
@mergify mergify bot dismissed rix0rrr’s stale review February 15, 2022 15:04

Pull request has been modified.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Feb 16, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 0e38f67
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit bb96621 into aws:master Feb 16, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Feb 16, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
* [x] Testing
  - Unit test added.
* [x] Docs
  - __jsdocs__: All public APIs documented
  - __README__: README and/or documentation topic updated

When creating a logs destination, an optional `role` can be passed to be assumed when writing logs in the destination.
 
Closes aws#7661.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@aws-cdk/aws-events Related to CloudWatch Events @aws-cdk/aws-logs Related to Amazon CloudWatch Logs @aws-cdk/aws-logs-destinations pr-linter/exempt-readme The PR linter will not require README changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logs: Allow overriding Role in addSubscriptionFilter

4 participants