-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataDogCloudFormation.yaml
158 lines (145 loc) · 4.91 KB
/
DataDogCloudFormation.yaml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
AWSTemplateFormatVersion: 2010-09-09
Description: EC2 Instance For Application Sever
Parameters:
APIKey:
Description: "The API key for your Datadog account"
Type: String
KeyName:
Description: Name of an existing EC2 key pair for SSH access to the EC2 instance
Type: AWS::EC2::KeyPair::KeyName
Default: aamirKP1
ConstraintDescription: must be the name of an existing EC2 KeyPair
InstaceTypeParam:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- m3.medium
- m3.large
- c3.large
- c3.xlarge
ConstraintDescription: Must be one of them
Mappings:
EC2RegionMapping:
us-east-1:
AMIs: ami-0ff8a91507f77f867
us-west-1:
AMIs: ami-0bdb828fd58c52235
eu-west-1:
AMIs: ami-047bb4163c506cd98
ap-northeast-1:
AMIs: ami-06cd52961ce9f0d85
ap-southeast-1:
AMIs: ami-08569b978cc4dfa10
Resources:
MyWebServerInstance:
Type: "AWS::EC2::Instance"
Metadata:
AWS::CloudFormation::Init:
configSets:
Install:
- "installHttpd"
- "installDatadogAgent"
Configure:
- "configureModStatus"
- "enableLogs"
- "configureLogs"
Restart:
- "restart"
installHttpd:
packages:
yum:
httpd: []
services:
sysvinit:
httpd:
enabled: true
ensureRunning: true
installDatadogAgent:
commands:
01_download_and_install:
env:
DD_API_KEY: !Sub "${APIKey}"
command: "bash -c \"$(curl -L https://raw.githubusercontent.com/DataDog/datadog-agent/master/cmd/agent/install_script.sh)\""
configureModStatus:
commands:
01_add_config:
command:
!Sub |
cat <<EOT > /etc/httpd/conf.d/server-status.conf
ExtendedStatus on
<Location /server-status>
SetHandler server-status
Allow from localhost
</Location>
EOT
enableLogs:
commands:
01_update_datadog_yaml:
cwd: "/etc/datadog-agent/"
command: "sed -i 's/^# logs_enabled: false$/logs_enabled: true/' datadog.yaml"
02_fix_logfile_permissions:
command: "setfacl -m u:dd-agent:rx /var/log/httpd"
03_sed_logrorate:
cwd: /etc/logrotate.d
command: "sed -i 's#/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true#/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true; setfacl -m u:dd-agent:rx /var/log/httpd#' httpd"
configureLogs:
commands:
01_create_apache_conf_yaml:
cwd: "/etc/datadog-agent/conf.d/apache.d/"
command:
cp conf.yaml.example conf.yaml
02_update_apache_conf_yaml:
cwd: "/etc/datadog-agent/conf.d/apache.d/"
command:
!Sub |
cat <<EOT >> conf.yaml
logs:
- type: file
path: /var/log/httpd/access_log
source: apache
sourcecategory: http_web_access
service: myservice
tags:
- env:qa
- type: file
path: /var/log/httpd/error_log
source: apache
sourcecategory: http_web_access
service: myservice
tags:
- env:qa
EOT
restart:
commands:
01_restart:
command: "systemctl restart httpd.service; systemctl stop datadog-agent.service; systemctl start datadog-agent.service"
Properties:
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource MyWebServerInstance --configsets Install,Configure,Restart --region ${AWS::Region}
InstanceType: !Ref "InstaceTypeParam"
ImageId: !FindInMap
- EC2RegionMapping
- !Ref AWS::Region
- AMIs
SecurityGroups:
- Ref: MySecurityGroup
MySecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Allow web traffic"
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: '80'
IpProtocol: tcp
ToPort: '80'
Outputs:
URL:
Description: "The URL of this instance's website"
Value: !Sub "http://${MyWebServerInstance.PublicIp}"
InstanceDashboard:
Description: "Link to this instances's Datadog dashboard"
Value: !Sub "https://app.datadoghq.com/dash/host_name/${MyWebServerInstance}"