- Newest
- Most votes
- Most comments
Creating an empty CloudWatch dashboard with one stack and then adding metrics to it from other stacks is not directly possible in the way you've described. The issue you're encountering is because CloudFormation treats the AWS::CloudWatch::Dashboard resource as a unique entity, and you can't have two resources with the same logical ID (in this case, the dashboard name) across different stacks.
However, there are alternative approaches you can consider to achieve a similar result:
-
Use a nested stack approach: Create a parent stack that defines the dashboard, and then use nested stacks to add widgets to it. This way, you're working within a single stack, but can still modularize your configuration.
-
Use a custom resource: Create a Lambda function as a custom resource in CloudFormation. This function can use the PutDashboard API to update the existing dashboard with new widgets. This approach allows you to add widgets from different stacks without creating a new dashboard resource.
-
Use AWS Systems Manager Parameter Store: Store the dashboard JSON in a parameter. Each stack can then retrieve the current dashboard configuration, modify it to add its widgets, and then update the dashboard using a custom resource.
-
Consolidate dashboard creation: If possible, consider creating the dashboard with all necessary widgets in a single stack. This approach is simpler but may not be feasible if you need to separate concerns across multiple stacks.
Remember, CloudWatch dashboards are global resources and not region-specific. When updating a dashboard, you need to include all existing widgets along with any new ones you want to add, as the update operation replaces the entire dashboard content.
While your original approach of creating separate dashboard resources in different stacks isn't possible, these alternative methods can help you achieve the desired outcome of having multiple stacks contribute to a single dashboard.
Sources
AWS::CloudWatch::Dashboard - AWS CloudFormation
Creating a CloudWatch dashboard - Amazon CloudWatch
PutDashboard - Amazon CloudWatch
Relevant content
- Accepted Answerasked 3 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago