Search code examples
amazon-web-servicesamazon-ec2gunicorn

How to send an e-mail/notification on gunicorn failure from AWS EC2


I have a python FastAPI project running on an AWS EC2 server. My gunicorn service failed without a specific error, I want to be notified of this so I can act upon it asap in my current architecture. Logs

I am evaluating using mailx or s-nail to setup an onfail trigger of e-mail


Solution

  • You can send email notifications via SNS. For that you'll have to,

    • Install Cloudwatch log agent on your EC2. (Details)
    • Create a Cloudwatch Log group and Log stream. Start sending logs to cloudwatch. (Details)
    • Create a Metric filter in Log Group and define Filter pattern to identify specific errors. (Details)
    • Create Cloudwatch Alarm based on the metric filter you have created and in the notification section select new topic and add your email address where you want to receive the notifications. (Details)