how to send Cloudwatch logs via email

3.1k views Asked by At

I'm working with aws codebuild and aws codepipeline.

In case the stage of aws codebuild failed I want to send the details via email.

Is it possible to send the cloudwatch logs via email?

1

There are 1 answers

0
Unsigned On

CodeBuild emits CloudWatch events when builds succeed or fail. You can use a combination of CloudWatch events, Lambda, and SES (Simple Email Service), to accomplish this:

  • Create a new CloudWatch rule:
    • CodeBuild > Build State Change > Specific state(s) > FAILED
  • Add a custom Lambda function target to the rule:
    • This function should call BatchGetBuilds with the failed build ARN, and use the logs information in the response to download the CloudWatch logs for the build.
    • Once the logs are downloaded, you can use SES to mail them to yourself.

For more information, see the sample on using CloudWatch Events with CodeBuild, or this one on sending emails with Amazon SES.