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

Commit e1848eb

Browse files
committed
Add ability to send certain logs that are written to while provisioning to Cloudwatch, to ease diagnosis of issue #114 or similar provisioning issues
1 parent 0f22f14 commit e1848eb

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ Resources:
257257
- Order: 2
258258
ComputeEnvironment: !Ref OnDemandComputeEnv
259259

260+
ContainerInstanceLogGroup:
261+
Type: AWS::Logs::LogGroup
262+
Properties:
263+
LogGroupName: "/aws/ecs/container-instance"
264+
RetentionInDays: 7
265+
260266
Outputs:
261267
DefaultJobQueueArn:
262268
Value: !Ref DefaultQueue

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Resources:
129129
- "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
130130
- "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
131131
- "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
132+
- "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
132133
BatchInstanceProfile:
133134
Type: AWS::IAM::InstanceProfile
134135
Properties:

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,72 @@ Resources:
9494
--==BOUNDARY==
9595
Content-Type: text/cloud-config; charset="us-ascii"
9696

97+
#cloud-config
98+
repo_update: true
99+
repo_upgrade: all
100+
97101
packages:
98102
- jq
99103
- btrfs-progs
100104
- sed
101105
- git
102106
- amazon-ssm-agent
103107
- unzip
108+
- amazon-cloudwatch-agent
104109

105110
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+
]
154+
}
155+
}
156+
}
157+
}
158+
EOF
159+
160+
# start the amazon-cloudwatch-agent
161+
- /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
162+
106163
# install aws-cli v2 and copy the static binary in an easy to find location for bind-mounts into containers
107164
- curl -s "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip"
108165
- unzip -q /tmp/awscliv2.zip -d /tmp

0 commit comments

Comments
 (0)