Skip to content

Commit

Permalink
Make sure Dashboards are named globaly unique
Browse files Browse the repository at this point in the history
  • Loading branch information
direnakkoc committed Oct 7, 2022
1 parent d976a93 commit 12a072b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion serverless-plugin/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ module.exports = function dashboard (serverless, dashboardConfig, functionDashbo
const dashboardResource = {
Type: 'AWS::CloudWatch::Dashboard',
Properties: {
DashboardName: `${context.stackName}Dashboard`,
// eslint-disable-next-line no-template-curly-in-string
DashboardName: { 'Fn::Sub': '${AWS::StackName}-${AWS::Region}-Dashboard' },
DashboardBody: { 'Fn::Sub': JSON.stringify(dash) }
}
}
Expand Down
6 changes: 4 additions & 2 deletions serverless-plugin/tests/dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ test('A dashboard includes metrics', (t) => {
const dashResources = cfTemplate.getResourcesByType('AWS::CloudWatch::Dashboard')
t.equal(Object.keys(dashResources).length, 1)
const [, dashResource] = Object.entries(dashResources)[0]
t.equal(dashResource.Properties.DashboardName, 'testStackDashboard')
// eslint-disable-next-line no-template-curly-in-string
t.same(dashResource.Properties.DashboardName, { 'Fn::Sub': '${AWS::StackName}-${AWS::Region}-Dashboard' })
const dashBody = JSON.parse(dashResource.Properties.DashboardBody['Fn::Sub'])

t.ok(dashBody.start)
Expand Down Expand Up @@ -276,7 +277,8 @@ test('A dashboard includes metrics for ALB', (t) => {
const dashResources = cfTemplate.getResourcesByType('AWS::CloudWatch::Dashboard')
t.equal(Object.keys(dashResources).length, 1)
const [, dashResource] = Object.entries(dashResources)[0]
t.equal(dashResource.Properties.DashboardName, 'testStackDashboard')
// eslint-disable-next-line no-template-curly-in-string
t.same(dashResource.Properties.DashboardName, { 'Fn::Sub': '${AWS::StackName}-${AWS::Region}-Dashboard' })
const dashBody = JSON.parse(dashResource.Properties.DashboardBody['Fn::Sub'])

t.ok(dashBody.start)
Expand Down

0 comments on commit 12a072b

Please sign in to comment.