Skip to content

feat(cloudwatch): add account id field for log query and metric widgets to support cross account visibility #34793

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

Merged
merged 6 commits into from
Jun 30, 2025

Conversation

ozelalisen
Copy link
Member

@ozelalisen ozelalisen commented Jun 23, 2025

Issue # (if applicable)

Closes #26105

Reason for this change

CloudWatch supports cross-account visibility for dashboards, allowing users to view metrics and logs from multiple AWS accounts in a single dashboard. However, the CDK CloudWatch construct library was missing the ability to specify the account ID for widgets, preventing users from creating cross-account dashboards using CDK.

Description of changes

I've added an optional accountId property to the following interfaces and classes:
• MetricWidgetProps interface in graph.ts (base interface for metric widgets)
• LogQueryWidgetProps interface in log-query.ts

This property is then passed through to the CloudWatch dashboard JSON for each widget type:
• AlarmWidget
• GraphWidget
• SingleValueWidget
• GaugeWidget
• TableWidget
• LogQueryWidget

I've also:
• Added comprehensive JSDoc documentation explaining the cross-account functionality
• Updated the README.md with a new section on cross-account visibility
• Updated unit tests to verify the accountId is properly included in the widget JSON
• Updated integration tests to demonstrate the feature

Design decisions:
• Made accountId optional to maintain backward compatibility
• Added the property to the base interfaces to ensure consistent implementation across widget types
• Provided clear documentation on prerequisites for cross-account functionality

Describe any new or updated permissions being added

No new IAM permissions are added by this change in the CDK code itself. However, users implementing cross-account CloudWatch dashboards will need to configure appropriate permissions between their accounts:

  1. The monitoring account must be set up as a monitoring account in CloudWatch settings
  2. The source account must grant permissions to the monitoring account using CloudWatch resource policies
  3. Appropriate IAM roles and policies must be configured as described in the AWS documentation

Description of how you validated changes

• Added unit tests for all widget types to verify the accountId property is correctly passed to the CloudWatch dashboard JSON
• Updated integration tests to include accountId in various widget configurations

Checklist

• [x] My code adheres to the CONTRIBUTING GUIDE and DESIGN GUIDELINES

@aws-cdk-automation aws-cdk-automation requested a review from a team June 23, 2025 16:39
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1 labels Jun 23, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jun 23, 2025
@ozelalisen ozelalisen marked this pull request as ready for review June 24, 2025 10:05
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jun 24, 2025
@leonmk-aws leonmk-aws self-assigned this Jun 25, 2025
Copy link
Contributor

@leonmk-aws leonmk-aws left a comment

Choose a reason for hiding this comment

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

Can you update the title to something that will better inform users in the changelog ? The current title doesn't really reflect that this adds support for cross account widget support

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jun 25, 2025
@ozelalisen ozelalisen changed the title feat(cloudwatch): add account id field for log query and metric widge… feat(cloudwatch): add account id field for log query and metric widgets to support cross account visibility Jun 25, 2025
@ozelalisen
Copy link
Member Author

ozelalisen commented Jun 25, 2025

@leonmk-aws

Can you update the title to something that will better inform users in the changelog ? The current title doesn't really reflect that this adds support for cross account widget support

Done

Copy link
Contributor

mergify bot commented Jun 26, 2025

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

Copy link
Contributor

mergify bot commented Jun 26, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated.

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@leonmk-aws
Copy link
Contributor

@Mergifyio requeue

Copy link
Contributor

mergify bot commented Jun 27, 2025

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

Copy link
Contributor

mergify bot commented Jun 27, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated.

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@leonmk-aws
Copy link
Contributor

@Mergifyio requeue

Copy link
Contributor

mergify bot commented Jun 27, 2025

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

Copy link
Contributor

mergify bot commented Jun 27, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated.

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@ozelalisen
Copy link
Member Author

@Mergifyio update

Copy link
Contributor

mergify bot commented Jun 30, 2025

update

❌ Mergify doesn't have permission to update

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/codecov-upload.yml without workflows permission

@ozelalisen
Copy link
Member Author

@Mergifyio rebase

Copy link
Contributor

mergify bot commented Jun 30, 2025

rebase

❌ Unable to rebase: user ozelalisen is unknown.

Please make sure ozelalisen has logged in Mergify dashboard.

@leonmk-aws
Copy link
Contributor

@Mergifyio rebase

Copy link
Contributor

mergify bot commented Jun 30, 2025

rebase

❌ Unable to rebase: user leonmk-aws is unknown.

Please make sure leonmk-aws has logged in Mergify dashboard.

Copy link
Contributor

mergify bot commented Jun 30, 2025

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

Copy link
Contributor

mergify bot commented Jun 30, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated.

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Contributor

mergify bot commented Jun 30, 2025

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

@mergify mergify bot merged commit ac4d09d into aws:main Jun 30, 2025
18 checks passed
Copy link
Contributor

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 Jun 30, 2025
@ozelalisen ozelalisen deleted the cloudwatch-cross-account branch July 25, 2025 15:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Cloudwatch LogQueryWidgetProps): (Lack of accountId filed)
3 participants