Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit a3f1070

Browse files
committed
Use cloud-init write_files module to create cloudwatch agent config file, and use the gwfcore namespace in the log group name
1 parent 7b01f2b commit a3f1070

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

src/templates/gwfcore/gwfcore-batch.template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Resources:
262262
ContainerInstanceLogGroup:
263263
Type: AWS::Logs::LogGroup
264264
Properties:
265-
LogGroupName: "/aws/ecs/container-instance"
265+
LogGroupName: "/aws/ecs/container-instance/${Namespace}"
266266
RetentionInDays: 7
267267

268268
Outputs:

src/templates/gwfcore/gwfcore-launch-template.template.yaml

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -107,55 +107,55 @@ Resources:
107107
- unzip
108108
- amazon-cloudwatch-agent
109109

110-
runcmd:
111-
112-
# create the amazon-cloudwatch-agent config file
113-
- |
114-
cat > /opt/aws/amazon-cloudwatch-agent/etc/config.json <<- EOF
115-
{
116-
"agent": {
117-
"logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
118-
},
119-
"logs": {
120-
"logs_collected": {
121-
"files": {
122-
"collect_list": [
123-
{
124-
"file_path": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log",
125-
"log_group_name": "/aws/ecs/container-instance",
126-
"log_stream_name": "/aws/ecs/container-instance/{instance_id}/amazon-cloudwatch-agent.log"
127-
},
128-
{
129-
"file_path": "/var/log/cloud-init.log",
130-
"log_group_name": "/aws/ecs/container-instance",
131-
"log_stream_name": "/aws/ecs/container-instance/{instance_id}/cloud-init.log"
132-
},
133-
{
134-
"file_path": "/var/log/cloud-init-output.log",
135-
"log_group_name": "/aws/ecs/container-instance",
136-
"log_stream_name": "/aws/ecs/container-instance/{instance_id}/cloud-init-output.log"
137-
},
138-
{
139-
"file_path": "/var/log/ecs/ecs-init.log",
140-
"log_group_name": "/aws/ecs/container-instance",
141-
"log_stream_name": "/aws/ecs/container-instance/{instance_id}/ecs-init.log"
142-
},
143-
{
144-
"file_path": "/var/log/ecs/ecs-agent.log",
145-
"log_group_name": "/aws/ecs/container-instance",
146-
"log_stream_name": "/aws/ecs/container-instance/{instance_id}/ecs-agent.log"
147-
},
148-
{
149-
"file_path": "/var/log/ecs/ecs-volume-plugin.log",
150-
"log_group_name": "/aws/ecs/container-instance",
151-
"log_stream_name": "/aws/ecs/container-instance/{instance_id}/ecs-volume-plugin.log"
152-
}
153-
]
110+
write_files:
111+
- permissions: '0644'
112+
path: /opt/aws/amazon-cloudwatch-agent/etc/config.json
113+
content: |
114+
{
115+
"agent": {
116+
"logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
117+
},
118+
"logs": {
119+
"logs_collected": {
120+
"files": {
121+
"collect_list": [
122+
{
123+
"file_path": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log",
124+
"log_group_name": "/aws/ecs/container-instance/${Namespace}",
125+
"log_stream_name": "/aws/ecs/container-instance/${Namespace}/{instance_id}/amazon-cloudwatch-agent.log"
126+
},
127+
{
128+
"file_path": "/var/log/cloud-init.log",
129+
"log_group_name": "/aws/ecs/container-instance/${Namespace}",
130+
"log_stream_name": "/aws/ecs/container-instance/${Namespace}/{instance_id}/cloud-init.log"
131+
},
132+
{
133+
"file_path": "/var/log/cloud-init-output.log",
134+
"log_group_name": "/aws/ecs/container-instance/${Namespace}",
135+
"log_stream_name": "/aws/ecs/container-instance/${Namespace}/{instance_id}/cloud-init-output.log"
136+
},
137+
{
138+
"file_path": "/var/log/ecs/ecs-init.log",
139+
"log_group_name": "/aws/ecs/container-instance/${Namespace}",
140+
"log_stream_name": "/aws/ecs/container-instance/${Namespace}/{instance_id}/ecs-init.log"
141+
},
142+
{
143+
"file_path": "/var/log/ecs/ecs-agent.log",
144+
"log_group_name": "/aws/ecs/container-instance/${Namespace}",
145+
"log_stream_name": "/aws/ecs/container-instance/${Namespace}/{instance_id}/ecs-agent.log"
146+
},
147+
{
148+
"file_path": "/var/log/ecs/ecs-volume-plugin.log",
149+
"log_group_name": "/aws/ecs/container-instance/${Namespace}",
150+
"log_stream_name": "/aws/ecs/container-instance/${Namespace}/{instance_id}/ecs-volume-plugin.log"
151+
}
152+
]
153+
}
154154
}
155155
}
156156
}
157-
}
158-
EOF
157+
158+
runcmd:
159159

160160
# start the amazon-cloudwatch-agent
161161
- /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/etc/config.json

0 commit comments

Comments
 (0)