-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCloudWatchAgents
109 lines (68 loc) · 2.39 KB
/
CloudWatchAgents
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
####################################################
AWS CloudWath Agent
####################################################
----*** Setting Up the Cloudwatch Agent ***----
>> Download the CloudWatch Agent
$ wget https://amazoncloudwatch-agent.s3.amazonaws.com/debian/amd64/latest/amazon-cloudwatch-agent.deb
$ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
----*** Create IAM Role ***----
- In policies -> CloudWatchAgentServerPolicy
- Create Role
>>> Allowing the CloudWatch agent to set log retention policy
- Select the Created Role
- In the Permissions tab, choose Add permissions, Create inline policy
- Choose the JSON tab
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "logs:PutRetentionPolicy",
"Resource": "*"
}
]
}
>>> Allowing the CloudWatch agent to fetch logs
- Select the Created Role
- In the Permissions tab, choose Add permissions, Create inline policy
- Choose the JSON tab
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnableCreationAndManagementOfCloudwatchLogEvents",
"Effect": "Allow",
"Action": [
"logs:GetLogEvents",
"logs:PutLogEvents"
],
"Resource": "*"
},
{
"Sid": "EnableCreationAndManagementOfCloudwatchLogGroupsAndStreams",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:PutRetentionPolicy",
"logs:CreateLogGroup"
],
"Resource": "*"
}
]
}
### Attach Role to Instance
----*** Create the CloudWatch agent configuration file ***----
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
CollectD - No
Advanced
Logs - /var/log/syslog
Xraytrace - No
SSM Paremeter - No
Config file location - /opt/aws/amazon-cloudwatch-agent/bin/config.json
----*** Start the agent ***----
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:<configuration-file-path>
>>> Check on CloudWatch Console
##### Troubleshooting
nano /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
-> Check log file path