GithubHelp home page GithubHelp logo

yottta / aws-logs-to-elk Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 14 KB

This repo contains different scripts needed to create everything is needed in order to forward EC2 logs to ELK

HCL 100.00%

aws-logs-to-elk's Introduction

EC2 logs forwarder to ELK

This repo contains different scripts needed to create everything is needed in order to forward EC2 logs to ELK.

Description

This is an example on how terraform can be used in order to provision the following:

  • a VPC with a public and a private subnet
  • two EC2 instances, every one of them in one of the subnets
  • necessary SGs that enable the communication between those 2 instances and also the communication with the rest of the world
  • docker executed applications that are storing their logs directly in journald
  • journald logs forwarded to CW
  • a Lambda function to process the logs and forward those to an ELK stack
  • a CW LogGroup trigger option for our Lambda function
  • and of course a bunch of IAM policies and roles needed for making all of the above points possible

Structure

ansible

Three playbooks needed in three different scenarios:

  • main.yml - playbook that is starting the whole provisioning process. Here the application for our Lambda function is built(a simple go application). This will be used for forwarding logs from CW to ELK. This playbook also executes the terraform scripts as well
  • setup_app.yml - playbook responsible with provisioning a lightweight application
  • setup_elk.yml - playbook that is responsible with provisioning the ElasticSearch and Kibana services

terraform

  • main.tf - the terraform script that contains everything needed to provision the needed AWS services in order to enable the logs forwarding
  • outputs.tf - here is defined what the terraform execution should print after it's done
  • secret.tfvars - file where you should update your aws_access_key and aws_secret_key

Dependencies

This whole repo used other repos. If you encounter issues, you can check those as well:

How do you execute this

Prerequisites

You should have installed the following:

  • docker
  • python (Python3 preferably)
  • ansible (2.5+)
  • unzip/zip
  • docker python packages

Configure it

In ansible/secret.tfvars put your AWS_ACCESS_KEY and AWS_SECRET_KEY. In keys/ generate a SSH key, preferably not secured with a passphrase ssh-keygen -t rsa -f aws_id_rsa

Provision

In ansible/ you have to execute the following command: ansible-playbook --connection=local --inventory localhost, main.yaml

Destroy

In ansible/ you have to execute the following command: ansible-playbook --connection=local --inventory localhost, --extra-vars "stack_state=absent" main.yaml

Navigate the results

After several minutes, you can get the public_dns from the public EC2 instance and putting it in a browser and accessing 5601 port (Kibana) you should see it loading. Also put in the index filtering just logs and save it. You should see the logs now.

aws-logs-to-elk's People

Contributors

yottta avatar

Stargazers

Vladislav Ashtaev 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.