1
- import { Construct , Lazy , Resource , Stack } from "@aws-cdk/core" ;
1
+ import { Construct , Lazy , Resource , Stack , Token } from "@aws-cdk/core" ;
2
2
import { CfnDashboard } from './cloudwatch.generated' ;
3
3
import { Column , Row } from "./layout" ;
4
4
import { IWidget } from "./widget" ;
@@ -10,9 +10,11 @@ export enum PeriodOverride {
10
10
11
11
export interface DashboardProps {
12
12
/**
13
- * Name of the dashboard
13
+ * Name of the dashboard.
14
14
*
15
- * @default Automatically generated name
15
+ * If set, must only contain alphanumerics, dash (-) and underscore (_)
16
+ *
17
+ * @default - automatically generated name
16
18
*/
17
19
readonly dashboardName ?: string ;
18
20
@@ -67,6 +69,16 @@ export class Dashboard extends Resource {
67
69
physicalName : props . dashboardName ,
68
70
} ) ;
69
71
72
+ {
73
+ const { dashboardName} = props ;
74
+ if ( dashboardName && ! Token . isUnresolved ( dashboardName ) && ! dashboardName . match ( / ^ [ \w - ] + $ / ) ) {
75
+ throw new Error ( [
76
+ `The value ${ dashboardName } for field dashboardName contains invalid characters.` ,
77
+ 'It can only contain alphanumerics, dash (-) and underscore (_).'
78
+ ] . join ( ' ' ) ) ;
79
+ }
80
+ }
81
+
70
82
new CfnDashboard ( this , 'Resource' , {
71
83
dashboardName : this . physicalName ,
72
84
dashboardBody : Lazy . stringValue ( { produce : ( ) => {
0 commit comments