GithubHelp home page GithubHelp logo

epwalsh / aws-log-monitor Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 761 KB

AWS Lambda function that monitors AWS CloudWatch logs for keywords :eyes: :eyes:

License: MIT License

Makefile 12.16% Shell 64.49% Python 23.35%
aws aws-lambda cloudwatch-logs

aws-log-monitor's Introduction

aws-log-monitor

This is an AWS Lambda function that monitors CloudWatch Log Streams for patterns, and sends Slack notifications to a channel when the pattern is found.

The choice of Slack as a destination is arbitrary and could easily be changed to something else, such as email.

By default, the key term is ERROR. So whenever ERROR occurs in a log stream being monitored, this information will be sent to Slack.

Requirements (OS X or Linux)

Make sure you have Python 3, pip, awscli, virtualenv, and virtualenvwrapper installed. If you already Python 3 and pip, just run the following:

pip install -r requirements.txt

If you've never used the AWS CLI before, see Configuring the AWS CLI. TLDR: you'll need to have an IAM user with programmatic access setup. Then you need to create two files ~/.aws/config and ~/.aws/credentials.

~/.aws/config will look something like this:

[default]
region=us-west-2

And ~/.aws/credentials will look something like this:

[default]
aws_access_key_id = *****
aws_secret_access_key = *****

Quick start in 5 minutes or less (OS X or Linux) ๐Ÿ‘ ๐Ÿ‘Œ ๐Ÿ‘ ๐Ÿ‘Œ ๐Ÿ™Œ ๐Ÿ‘

1. Run the bootstraping script.

Run ./bootstrap.sh. This will:

  • Create a Python 3 virtualenv called log-monitor.
  • Install the application requirements (./lambda/requirements.txt) to that virtualenv.
  • Create a symbolic link ./lambda/packages to the site-packages directory of that virtualenv, so that all of the dependencies can be bundled together in the deployment package.
  • Create an IAM policy that gives the lambda function certain permissions.
  • Create a role for the Lambda function to use, and attach the policy to that role.
  • Build a deployment package.
  • Create a Lambda function on AWS with the role attached and upload the deployment package.

2. Set up a Slack bot user. ๐Ÿ‘พ

If you don't have one already, see Create a bot for your workspace.

Once the bot user has been created, grab the API token from the bot settings page and add it as an environment variable to the Lambda function through the AWS Lambda console like so:

environment.png

The last thing you need to do in order for the Lambda function to be able to deliver messages to Slack is to create a Slack channel and invite the bot user to that channel. You can do this through the Slack dashboard or application. By default, the Lambda function assumes the channel name is "logs", but you can change that by setting the environment variable TARGET_SLACK_CHANNEL in the same way that you just set the API token environment variable above.

3. Set up a log group to monitor.

The Lambda function should now be deployed to AWS, but we will need to point it to at least one log group to verify that it works. We'll just create a dummy log group here for testing.

Navigate the AWS CloudWatch console, click on "Logs" on the left panel and then "Create log group", and enter the name "test-group" as shown here:

log-group.png

Then create a new log stream within the log group called "test-stream":

log-group.png

Lastly, to get the Lambda function to start monitoring the new log group we just created, run the following make command:

make add-log-group log-group=/aws/test-group id=test-group

That's it! You can now send a fake error message into the log stream to test if it works:

make test log-group=/aws/test-group message="ERROR" log-stream=test-stream

Happy logging! ๐Ÿ˜Ž

aws-log-monitor's People

Contributors

epwalsh avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.