-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodule.yml
More file actions
78 lines (78 loc) · 2.98 KB
/
module.yml
File metadata and controls
78 lines (78 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
# Copyright 2018 widdix GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
AWSTemplateFormatVersion: '2010-09-09'
Description: 'cfn-modules: CloudWatch Dashboard'
# cfn-modules:implements()
Parameters:
DashboardName:
Description: 'The name for the dashboard'
Type: String
AllowedPattern: '^[A-Za-z0-9-_]{1,255}$'
ConstraintDescription: 'Only A-Z, a-z, 0-9, -, and _ are supported. Max 255 characters.'
AlbModule:
Description: 'Optional stack name of the alb module.'
Type: String
Default: ''
FargateServiceModule:
Description: 'Optional stack name of the fargate-service module.'
Type: String
Default: ''
RdsAuroraServerlessModule:
Description: 'Optional stack name of the rds-aurora-serverless module.'
Type: String
Default: ''
Conditions:
HasAlbModule: !Not [!Equals [!Ref AlbModule, '']]
HasFargateServiceModule: !Not [!Equals [!Ref FargateServiceModule, '']]
HasRdsAuroraServerlessModule: !Not [!Equals [!Ref RdsAuroraServerlessModule, '']]
Resources:
CloudWatchDashboardPolicy:
Type: 'AWS::IAM::ManagedPolicy'
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'cloudwatch:DeleteDashboards'
- 'cloudwatch:PutDashboard'
Resource: '*'
DashboardFunction:
Type: 'AWS::CloudFormation::Stack'
Properties:
Parameters:
Handler: 'dashboard.handler'
Runtime: 'nodejs18.x'
Timeout: '30'
ManagedPolicyArns: !Ref CloudWatchDashboardPolicy
TemplateURL: './node_modules/@cfn-modules/lambda-function/module.yml'
Dashboard:
Type: 'Custom::Dashboard'
Version: '1.0'
Properties:
DashboardName: !Ref DashboardName
AlbFullName: !If [HasAlbModule, {'Fn::ImportValue': !Sub '${AlbModule}-LoadBalancerFullName'}, !Ref 'AWS::NoValue']
FargateServiceName: !If [HasFargateServiceModule, {'Fn::ImportValue': !Sub '${FargateServiceModule}-ServiceName'}, !Ref 'AWS::NoValue']
FargateServiceClusterName: !If [HasFargateServiceModule, {'Fn::ImportValue': !Sub '${FargateServiceModule}-ClusterName'}, !Ref 'AWS::NoValue']
RdsClusterName: !If [HasRdsAuroraServerlessModule, {'Fn::ImportValue': !Sub '${RdsAuroraServerlessModule}-ClusterName'}, !Ref 'AWS::NoValue']
Region: !Ref 'AWS::Region'
ServiceToken: !GetAtt 'DashboardFunction.Outputs.Arn'
Outputs:
ModuleId:
Value: 'cloudwatch-dashboard'
ModuleVersion:
Value: '1.7.0'
StackName:
Value: !Ref 'AWS::StackName'