Skip to content
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(events-targets): add toggle to opt out of resource policy creation for targeted log group #32242

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

gwaltneyluke
Copy link

Issue # (if applicable)

Closes #31404.

Reason for this change

When a CloudWatch LogGroup is set as the target of an EventBridge rule, a custom resource creates a Log Resource Policy to establish trust so that EventBridge can write messages to CloudWatch. However, there is a strict limit of 10 CloudWatch Log Resource Policies per account per region. This therefore limits the amount of EventBridge rules an account can have writing to CloudWatch.

Description of changes

The optional property createLogGroupResourcePolicy has been added to the LogGroupProps interface. When omitted or set to true, the Resource Policy is created just as the functionality exists today. When set to false, the Resource Policy is not created. The trust between EventBridge and CloudWatch must be established manually.

Description of how you validated changes

Unit tests have been added and are passing. Existing integration tests are passing.

Code was also linked to an existing project, where the new property was toggled on and off. When on, the CloudWatch LogGroup Resource Policy was created, and messages sent to EventBridge were making it to the LogGroup. When off, the CloudWatch LogGroup Resource Policy was NOT created, but a custom Resource Policy still allowed messages sent to the EventBridge to end up in the LogGroup.

Checklist


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

@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Nov 22, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team November 22, 2024 00:31
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Nov 22, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation dismissed their stale review November 22, 2024 01:37

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 22, 2024
@aws-cdk-automation
Copy link
Collaborator

This PR has been in the MERGE CONFLICTS state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Feb 10, 2025
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2025
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 10, 2025
@aaythapa aaythapa reopened this Feb 10, 2025
Copy link
Contributor

@aaythapa aaythapa left a comment

Choose a reason for hiding this comment

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

Thanks for contributing! Changes look good, just a couple nits and a question. I see there are some merge conflicts as well.

to set `installLatestAwsSdk` to `true`. This may be problematic for CN partition deployment. To
workaround this issue, set `installLatestAwsSdk` to `false`.
By default, the CloudWatch LogGroup target will create a LogGroup Resource Policy which allows
EventBridge to write to the target LogGroup. If you want to manage this trust relationship manually,
Copy link
Contributor

Choose a reason for hiding this comment

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

How is the trust relationship managed manually? Is there a way we can make it easier through a property? If there is then we should go with that and my thinking is if they set that property then we don't make a resource policy. So the property will not only opt users out of making resource policies but make it easier to manage the trust. What are your thoughts on this?

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking the trust relationship would be managed with a pre-existing Log Group Resource Policy that allows EventBridge to write to any log group with a specific prefix (ex: /aws/events/). This way we can have several rules write to different log groups and that trust is managed by a single policy. This might be a little too coarse a policy, though.

Another idea would be to provide an existing Log Group Resource Policy to this method, and the method can add a statement to that policy which allows EventBridge to write to the specified log group, rather than adding a whole new policy.

Comment on lines +138 to +140
The CloudWatch LogGroup Resource Policy is created using an AWS custom resource internally which will
default to set `installLatestAwsSdk` to `true`. This may be problematic for CN partition deployment.
To workaround this issue, set `installLatestAwsSdk` to `false`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Thanks for adding

* Whether a CloudWatch LogGroup Resource Policy will be
* created to allow EventBridge to write to the LogGroup
*
* @default - create the CloudWatch LogGroup Resource Policy
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
* @default - create the CloudWatch LogGroup Resource Policy
* @default - true (create the CloudWatch LogGroup Resource Policy)

Copy link
Author

Choose a reason for hiding this comment

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

done!

Comment on lines 126 to 128
const createLogGroupResourcePolicy = this.props.createLogGroupResourcePolicy !== undefined ?
this.props.createLogGroupResourcePolicy :
true;
Copy link
Contributor

@aaythapa aaythapa Feb 10, 2025

Choose a reason for hiding this comment

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

nit:

Suggested change
const createLogGroupResourcePolicy = this.props.createLogGroupResourcePolicy !== undefined ?
this.props.createLogGroupResourcePolicy :
true;
const createLogGroupResourcePolicy = this.props.createLogGroupResourcePolicy ?? true;

Copy link
Author

Choose a reason for hiding this comment

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

done!

@aaythapa aaythapa self-assigned this Feb 10, 2025
@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aaythapa aaythapa reopened this Feb 12, 2025
@aaythapa aaythapa added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 12, 2025
@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aaythapa aaythapa reopened this Feb 13, 2025
@aws aws unlocked this conversation Feb 13, 2025
@aaythapa aaythapa added pr-linter/do-not-close The PR linter will not close this PR while this label is present and removed closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. labels Feb 13, 2025
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 13, 2025
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 6a30077
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. pr-linter/do-not-close The PR linter will not close this PR while this label is present
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-events-target: support adding CloudWatchLogGroup rule target without creation of new Resource Policy
3 participants