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

Commit 784d4c5

Browse files
authored
Merge pull request #127 from tthyer/misc-cloudwatch-logging
Ship logs to cloudwatch to diagnose provisioning errors
2 parents 9c73fad + 05d4805 commit 784d4c5

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Resources:
128128
Type: MANAGED
129129
State: ENABLED
130130
ComputeResources:
131+
Ec2Configuration:
132+
- ImageType: ECS_AL2
131133
AllocationStrategy: SPOT_CAPACITY_OPTIMIZED
132134
# Set the Spot price to 100% of on-demand price
133135
# This is the maximum price for spot instances that Batch will launch.
@@ -257,6 +259,12 @@ Resources:
257259
- Order: 2
258260
ComputeEnvironment: !Ref OnDemandComputeEnv
259261

262+
ContainerInstanceLogGroup:
263+
Type: AWS::Logs::LogGroup
264+
Properties:
265+
LogGroupName: !Sub "/aws/ecs/container-instance/${Namespace}"
266+
RetentionInDays: 7
267+
260268
Outputs:
261269
DefaultJobQueueArn:
262270
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: security
100+
97101
packages:
98102
- jq
99103
- btrfs-progs
100104
- sed
101105
- git
102106
- amazon-ssm-agent
103107
- unzip
108+
- amazon-cloudwatch-agent
109+
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+
}
154+
}
155+
}
156+
}
104157
105158
runcmd:
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)