

# Create tag-based Amazon CloudWatch dashboards automatically
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically"></a>

*Janak Vadaria, Vinodkumar Mandalapu, and RAJNEESH TYAGI, Amazon Web Services*

## Summary
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-summary"></a>

Creating different Amazon CloudWatch dashboards manually can be time-consuming, particularly when you have to create and update multiple resources to automatically scale your environment. A solution that creates and updates your CloudWatch dashboards automatically can save you time. This pattern helps you deploy a fully automated AWS Cloud Development Kit (AWS CDK) pipeline that creates and updates CloudWatch dashboards for your AWS resources based on tag change events, to display Golden Signals metrics.

In site reliability engineering (SRE), Golden Signals refers to a comprehensive set of metrics that offer a broad view of a service from a user or consumer perspective. These metrics consist of latency, traffic, errors, and saturation. For more information, see [What is Site Reliability Engineering (SRE)?](https://aws.amazon.com/what-is/sre/) on the AWS website.

The solution provided by this pattern is event-driven. After it's deployed, it continuously monitors the tag change events and automatically updates the CloudWatch dashboards and alarms.

## Prerequisites and limitations
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-prereqs"></a>

** Prerequisites **
+ An active AWS account
+ AWS Command Line Interface (AWS CLI), [installed and configured](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
+ [Prerequisites](https://docs.aws.amazon.com/cdk/v2/guide/work-with.html#work-with-prerequisites) for the AWS CDK v2
+ A [bootstrapped environment](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html) on AWS
+ [Python version 3](https://www.python.org/downloads/)
+ [AWS SDK for Python (Boto3)](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html), installed
+ [Node.js version 18](https://nodejs.org/en/download/current) or later
+ Node package manager (npm), [installed and configured](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) for the AWS CDK
+ Moderate (level 200) familiarity with the AWS CDK and AWS CodePipeline

**Limitations**

This solution currently creates automated dashboards for the following AWS services only:
+ [Amazon Relational Database Service (Amazon RDS)](https://aws.amazon.com/rds/)
+ [AWS Auto Scaling](https://aws.amazon.com/autoscaling/)
+ [Amazon Simple Notification Service (Amazon SNS)](https://aws.amazon.com/sns/)
+ [Amazon DynamoDB](https://aws.amazon.com/dynamodb/)
+ [AWS Lambda](https://aws.amazon.com/lambda/)

## Architecture
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-architecture"></a>

**Target technology stack**
+ [CloudWatch dashboards](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)
+ [CloudWatch alarms](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)

**Target architecture**

![\[Target architecture for creating tag-based CloudWatch dashboards\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/images/pattern-img/f234fe30-87db-446f-a291-d33928ca2ccb/images/f63ca697-f252-416d-8a1b-0239f38c10c5.png)


1. An AWS tag change event for the configured application tags or code changes initiates a pipeline in AWS CodePipeline to build and deploy updated CloudWatch dashboards.

1. AWS CodeBuild runs a Python script to find the resources that have configured tags and stores the resource IDs in a local file in a CodeBuild environment.

1. CodeBuild runs **cdk synth** to generate CloudFormation templates that deploy CloudWatch dashboards and alarms.

1. CodePipeline deploys the CloudFormation templates to the specified AWS account and Region.

1. When the CloudFormation stack has been deployed successfully, you can view the CloudWatch dashboards and alarms.

**Automation and scale**

This solution has been automated by using the AWS CDK. You can find the code in the GitHub [Golden Signals Dashboards on Amazon CloudWatch](https://github.com/aws-samples/golden-signals-dashboards-sample-app) repository. For additional scaling and to create custom dashboards, you can configure multiple tag keys and values.

## Tools
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-tools"></a>

**Amazon services**
+ [Amazon EventBridge](https://aws.amazon.com/eventbridge/) is a serverless event bus service that helps you connect your applications with real-time data from a variety of sources, including AWS Lambda functions, HTTP invocation endpoints using API destinations, or event buses in other AWS accounts.
+ [AWS CodePipeline](https://aws.amazon.com/codepipeline/) helps you quickly model and configure the different stages of a software release and automate the steps required to release software changes continuously.
+ [AWS CodeBuild](https://aws.amazon.com/codebuild/) is a fully managed build service that helps you compile source code, run unit tests, and produce artifacts that are ready to deploy.
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) is an open source tool that helps you interact with AWS services through commands in your command-line shell.
+ [AWS Identity and Access Management (IAM)](https://aws.amazon.com/iam/) helps you securely manage access to your AWS resources by controlling who is authenticated and authorized to use them.
+ [Amazon Simple Storage Service (Amazon S3)](https://aws.amazon.com/s3/) is a cloud-based object storage service that helps you store, protect, and retrieve any amount of data.

## Best practices
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-best-practices"></a>

As a security best practice, you can use encryption and authentication for the source repositories that connect to your pipelines. For additional best practices, see [CodePipeline best practices and use cases](https://docs.aws.amazon.com/codepipeline/latest/userguide/best-practices.html) in the CodePipeline documentation.

## Epics
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-epics"></a>

### Configure and deploy the sample application
<a name="configure-and-deploy-the-sample-application"></a>


| Task | Description | Skills required | 
| --- | --- | --- | 
| Configure and deploy the sample application. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/create-tag-based-amazon-cloudwatch-dashboards-automatically.html) | AWS DevOps | 
| Automatically create dashboards and alarms. | After you deploy the sample application, you can create any of the resources that this solution supports with expected tag values, which will automatically create the specified dashboards and alarms.To test this solution, create an AWS Lambda function:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/create-tag-based-amazon-cloudwatch-dashboards-automatically.html) | AWS DevOps | 

### Remove the sample application
<a name="remove-the-sample-application"></a>


| Task | Description | Skills required | 
| --- | --- | --- | 
| Remove the `golden-signals-dashboard` construct. | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/create-tag-based-amazon-cloudwatch-dashboards-automatically.html) | AWS DevOps | 

## Troubleshooting
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-troubleshooting"></a>


| Issue | Solution | 
| --- | --- | 
| Python command not found (referring to `findresources.sh`, line 8).  | Check the version of your Python installation. If you have installed Python version 3, replace `python` with `python3` on line 8 of the `resources.sh` file, and run the `sh deploy.sh` command again to deploy the solution. | 

## Related resources
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-resources"></a>
+ [Bootstrapping](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html) (AWS CDK documentation)
+ [Using named profiles](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-methods) (AWS CLI documentation)
+ [AWS CDK Workshop](https://cdkworkshop.com/)

## Additional information
<a name="create-tag-based-amazon-cloudwatch-dashboards-automatically-additional"></a>

The following illustration shows a sample dashboard for Amazon RDS that is created as part of this solution.

![\[Sample dashboard for Amazon RDS\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/images/pattern-img/f234fe30-87db-446f-a291-d33928ca2ccb/images/706a262f-8650-47ff-ac44-e04ce5f4023e.png)
