To create a CloudWatch Dashboard in CloudFormation, you must supply the dashboard's source code as a stringified JSON rather than as a separate JSON structure.
This is annoying because my JSON has to be escaped inside of a string literal within my serverless.yml:
...
resources:
Resources:
MyDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: My-Dashboard
DashboardBody: "{\"widgets\": [...]}"
I tried using a file reference:
...
resources:
Resources:
MyDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: My-Dashboard
DashboardBody: ${file(my-dashboard.json)}
but serverless inserts the content as part of the YAML structure, rather than as part of the JSON string:
...
resources:
Resources:
MyDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: My-Dashboard
DashboardBody:
Widgets:
- ...
- ...
Is there a way to stringify the JSON from my-dashboard.json?