How can the SysOps administrator automate the creation of the CloudWatch dashboard each time the application is deployed?
Create a script by using the AWS CLI to run the aws cloudformation put-dashboard command with the name of the dashboard. Run the command each time a new CloudFormation stack is created.
Export the existing CloudWatch dashboard as JSON. Update the CloudFormation template to define an AWS::CloudWatch::Dashboard resource. Include the exported JSON in the resource’s DashboardBody property.
Update the CloudFormation template to define an AWS::CloudWatch::Dashboard resource. Use the Intrinsic Ref function to reference the ID of the existing CloudWatch dashboard.
Update the CloudFormation template to define an AWS::CloudWatch::Dashboard resource. Specify the name of the existing dashboard in the DashboardName property.
Explanations:
Theaws cloudformation put-dashboardcommand is not used in CloudFormation templates. Instead, dashboards should be defined directly within the CloudFormation template using theAWS::CloudWatch::Dashboardresource.
Exporting the CloudWatch dashboard as JSON and including it in the CloudFormation template via theDashboardBodyproperty is the correct way to automate dashboard creation. The dashboard JSON defines the layout and settings.
TheReffunction is used to reference resources within the same stack, but it does not work to reference an existing CloudWatch dashboard, which must be defined explicitly in the CloudFormation template.
Specifying the name of an existing CloudWatch dashboard in theDashboardNameproperty is incorrect. The dashboard must be defined in the CloudFormation template, not referenced by name.