Giter Site home page Giter Site logo

jmfuchs / aws-cloudtrail-processing Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 916 KB

A serverless application for processing AWS CloudTrail logs.

License: Apache License 2.0

Python 100.00%
serverless-framework aws lambda elasticsearch cloudtrail logging

aws-cloudtrail-processing's Introduction

Processing CloudTrail Logs with AWS Lambda

This serverless application creates the necessary resources and integrations for properly enabling and processing CloudTrail logs in your environment. The below architecture showcases how logs are stored, post-processed, and pushed to Elasticsearch.

Architecture

Log-Architecture

Prerequisites

Below are the necessary prerequisites:

Cloud9 Environment

If you have trouble installing any of the prerequisites or dependencies, you can spin up an AWS Cloud9 environment, which is a cloud-based IDE that comes prepackaged with a number of essential packages. After which you can run the following command to install the Serverless Framework.

npm install -g serverless

Set Variables

Clone the repo and open up environment/dev.yml and add in the appropiate variables.

You can add new files for different environments.

Enrich Logs

Since the Lambda Function parses through every CloudTrail event, you can enrich the event by adding additional information to complement data points and add context. This can either be static data hardcoded in the Lambda function or it can be dynamically pulled from a DynamoDB table or 3rd party threat intelligence.

Open cloudtrail.py, find the section of code below, and add additional metadata as necessary:

############# Add additional metadata to event #############
            
# Example: Add AWS Account type
i["accountType"] = "Production" 

############################################################

Install Dependencies

Ensure you are in the aws-ct-processing directory and run the following to install the dependencies:

pip install -r requirements.txt -t ./

Deploy

To deploy the serverless application, run the following command:

sls deploy -s dev -r us-west-2

If you've created different environment files that reference other aws profiles or you want to deploy to different regions, you can replace dev and us-west-2 as necessary.

Access

After to the application has been successfully deployed you can view the logs in Kibana by doing the following:

  • Go to the AWS Elasticsearch console.
  • Click on the Domain that starts with sls-aws-ct-processing.
  • Click the link next to Kibana.

Once you are in Kibana:

  • Click Management in the left Navigation.
  • Click Index Patterns
  • For Step 1 (Define index pattern) type logs-*.
  • For Step 2 (Configure Settings) select @timestamp.
  • Click Create Index Pattern.
  • On the left navigation, click Discover to view your events.

Cleanup

Below are the steps to cleanup this application:

  • Manually delete the S3 bucket you specificed in the dev.yml file.

    You have to manually delete this bucket because there is now data in the bucket and as a protection mechanism CloudFormation will not delete buckets it created if data exists in that bucket.

  • Run the below command to delete the serverless application

    sls remove  -s dev -r us-west-2
    

aws-cloudtrail-processing's People

Contributors

jmfuchs avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

arrayly

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.