20-02-2019, 02:03 PM
(20-02-2019, 06:16 AM)subham Wrote: Thanks ..It was a great help.
You're welcome.
Here is the upgraded version of the template that allows you to use variables input by user into the template using "Ref" with "Fn::Join"
Code:
JSON
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation Template Auto Dashboard Creation",
"Metadata" : {"Created By": "Faizal Khan @ Ecomm India Cloud IT"},
"Parameters": {
"Server1CPU": {
"Description": "What is the instance id of Server 1 for CPU Utilization?",
"Type": "String"
},
"Server2CPU": {
"Description": "What is the instance id of Server 2 for CPU Utilization?",
"Type": "String"
},
"EBS1Disk": {
"Description": "What is the volume id of Disk 1 for Volume Read Ops?",
"Type": "String"
},
"EBS2Disk": {
"Description": "What is the volume id of Disk 2 for Volume Read Ops?",
"Type": "String"
}
},
"Resources": {
"AutomatedDashboard": {
"Type": "AWS::CloudWatch::Dashboard",
"Properties": {
"DashboardName": "Dashboard-Multiple-EC2-EBS-Metrics",
"DashboardBody": {
"Fn::Join": [
"",
[
"{\"widgets\":[{\"type\":\"metric\",\"x\":0,\"y\":0,\"width\":12,\"height\":6,\"properties\":{\"metrics\":[[\"AWS/EC2\",\"CPUUtilization\",\"InstanceId\",\"",
{
"Ref": "Server1CPU"
},
"\"],[\".\",\".\",\".\",\"",
{
"Ref": "Server2CPU"
},
"\"]],\"period\":300,\"stat\":\"Average\",\"region\":\"us-east-1\",\"title\":\"EC2 Instances CPU Utilization\"}},{\"type\":\"metric\",\"x\":12,\"y\":0,\"width\":12,\"height\":6,\"properties\":{\"metrics\":[[\"AWS/EBS\",\"VolumeReadOps\",\"VolumeId\",\"",
{
"Ref": "EBS1Disk"
},
"\"],[\".\",\".\",\".\",\"",
{
"Ref": "EBS2Disk"
},
"\"]],\"period\":300,\"stat\":\"Average\",\"region\":\"us-east-1\",\"title\":\"EBS Volumes ReadOps\"}}]}"
]
]
}
}
}
}
}
YAML
AWSTemplateFormatVersion: 2010-09-09
Description: AWS CloudFormation Template Auto Dashboard Creation
Metadata:
Created By: Faizal Khan @ Ecomm India Cloud IT
Parameters:
Server1CPU:
Description: What is the instance id of Server 1 for CPU Utilization?
Type: String
Server2CPU:
Description: What is the instance id of Server 2 for CPU Utilization?
Type: String
EBS1Disk:
Description: What is the volume id of Disk 1 for Volume Read Ops?
Type: String
EBS2Disk:
Description: What is the volume id of Disk 2 for Volume Read Ops?
Type: String
Resources:
AutomatedDashboard:
Type: 'AWS::CloudWatch::Dashboard'
Properties:
DashboardName: Dashboard-Multiple-EC2-EBS-Metrics
DashboardBody: !Join
- ''
- - >-
{"widgets":[{"type":"metric","x":0,"y":0,"width":12,"height":6,"properties":{"metrics":[["AWS/EC2","CPUUtilization","InstanceId","
- !Ref Server1CPU
- '"],[".",".",".","'
- !Ref Server2CPU
- >-
"]],"period":300,"stat":"Average","region":"us-east-1","title":"EC2
Instances CPU
Utilization"}},{"type":"metric","x":12,"y":0,"width":12,"height":6,"properties":{"metrics":[["AWS/EBS","VolumeReadOps","VolumeId","
- !Ref EBS1Disk
- '"],[".",".",".","'
- !Ref EBS2Disk
- >-
"]],"period":300,"stat":"Average","region":"us-east-1","title":"EBS
Volumes ReadOps"}}]}