Home > Back-end >  Is there any way to trigger an AWS Lambda if Cloudwatch logs haven't been updated in X amount o
Is there any way to trigger an AWS Lambda if Cloudwatch logs haven't been updated in X amount o

Time:07-27

I have some ECS tasks running in AWS Fargate which in very rare cases may "die" internally, but will still show as "RUNNING" and not fail and trigger the task to restart.

What I would like to do, if possible is check for the absence of logs, e.g. if logs haven't been written in 30 minutes, trigger a lambda to kill the ECS task which will cause it to start back up.

The health check functionality isn't sufficient.

If this isn't possible, are there any other approaches I could consider?

CodePudding user response:

you can have metric and anomaly detection but it may cost for metric to process logs alarm may cost too. Would rather do lambda run every 30min which would check if logs are there and then would kill ECS as needed. you can run lambda on interval with cloudwatch events bridge.

Logs are probably sent to cloudwatch logs group from your ECS, if you have static name of the logs group, you can use SDK to describe streams inside the group. This api call will tell you timestamp of the last data in stream.

inside lambda nodejs context aws-sdk v2 is already present, so you can require w/o install. here is doc for v2:

enter image description here

  • Related