AWS Cloudfront Real-Time Logging Stack

aws-cf-rtl

AWS Cloudfront Real-Time Logging

Why?

AWS Cloudfront easily stashes JSON formatted weblogs to S3 buckets (standard logging). However, processing raw JSON files from an S3 bucket is tedious. One can manually update Athena tables to query the data or write custom fetcher/parsers to query the JSON files. To solve the issue, Cloudfront offers a Real-time logging feature that allows you to stream logs to Kinesis in real-time. The downside, however, is that setting up the stack from scratch is a bit of a hassle. This repo aims to provide a nearly one-shot Cloudformation template to set up and run the Real-Time Logging feature.

What's in the Box?

This repo provides an AWS Cloudformation template to stand up a basic Cloudfront Real-Time Logging (RTL) service. Items included in the repo:

  • Cloudformation template.
  • Cloudfront Real-Time Logging (RTL) configuration.
  • AWS Glue database, table, and crawler.
  • Kinesis stream and Firehose delivery stream (with output conversion to ORC).
  • AWS Lambda function to process raw Cloudfront logs into a Glue table-compatible JSON format.
  • Basic IAM roles and policies. Note: THESE ROLES AND POLICES ARE NOT PRODUCTION-READY.
  • S3 bucket for storing raw and processed ORC formatted logs.
  • Helper CLI tools:
    • Process user-agent strings into browser and device type.
    • Process IP addresses into GeoIP data.
    • Raw log re-drive to Kinetisis stream.

Assumtions: things you should already know or have.

  • You have an AWS account with Cloudfront distributions already deployed.
  • Go >= 1.17 installed and configured.
  • Some level of experience editing AWS Cloudformation templates.
  • Be aware: any changes to the data fields selected for real-time logging must be reflected in the Lambda function code and the Glue table schema defined in the template.

Getting Started

  • Edit aws-cloudformation/template.yaml to suit your needs. At a minimum, you should edit/verify the Parameters section.
  • Review IAM Policies and Roles and edit to suit your needs.
  • Review and edit the Makefile, adjusting parameters for your environment. In general, all Cloudfront activites take place in AWS region us-east-1.
  • Run make deploy to build the Lambda function deploy the Cloudformation template.
  • Add Cloudfront distributions to the Real-Time Logging service (see Real-time logs for more information).
  • Inkoke hits to the Cloudfront distribution(s).
  • Wait at least five minutes for the logs to be processed. Check Cloudwatch logs execution results and errors.
  • Check S3 bucket for backup and processed files.

Next steps

Once you have a full configuration deployed and functional, you can run the provided Glue Crawler to process the ORC formatted logs. Next, use Athena or Trino to query the Glue table.

Feedback

Feedback, comments, pull requests, and questions are welcome.

Owner
Robert Sigler
I write code to make my life easier. Issues, pull requests, and constructive conversations are always welcome. My gists are my nerd notes.
Robert Sigler
Similar Resources

Aws-cognito-demo-go - Source code for AWS Cognito in Go

AWS Cognito Demo in Go Source code for YouTube series, AWS Cognito in Go - https

Dec 10, 2022

Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

May 7, 2022

Aws-cdk-go-examples - Example projects using the AWS CDK by Golang

aws-cdk-go-examples Example projects using the AWS CDK by Golang Useful commands

Nov 24, 2022

Delete CloudFormation stacks respecting stack dependencies

Delete CloudFormation stacks respecting stack dependencies

CFN Teardown Cleanup CloudFormation stacks respecting the order of dependencies. Features Stack name pattern matching for deletion. Finds out dependen

Oct 9, 2022

Stack-oriented programming language

aiur Stack-oriented programming language TODO Operators If statements Loops Procedures Include statements Package manager Syntax Conditional conditio

May 20, 2022

Creating an API for an ecommerce with real scenarios

Creating an API for an ecommerce with real scenarios

Nagini Api Este projeto está sendo criado com a intenção de estudo e ao mesmo te

Jan 19, 2022

AWS SDK for the Go programming language.

AWS SDK for Go aws-sdk-go is the official AWS SDK for the Go programming language. Checkout our release notes for information about the latest bug fix

Dec 31, 2022

Simple tool to search tagged resources between all AWS resouces

Welcome to Cloud Inventory Tags 👋 Simple tool to search tagged resources around all AWS Account Installation MacOS / OSX

Jan 26, 2022

Assume AWS IAM roles from GitHub Actions workflows with no stored secrets

Assume AWS IAM roles from GitHub Actions workflows with no stored secrets

AWS IAM roles for GitHub Actions workflows Background and rationale GitHub Actions are a pretty nice solution for CI/CD. Where they fall short is inte

Feb 12, 2022
Lambda stack to turn off and destroy all resources from your personal AWS Account to avoid billing surprises
Lambda stack to turn off and destroy all resources from your personal AWS Account to avoid billing surprises

AWS, Turn off my Account, please Lambda stack to turn off and destroy all resources from your personal AWS Account to avoid billing surprises Resource

Oct 25, 2022
🐥 Sturdy is an open-source, real-time, version control platform for startups
🐥 Sturdy is an open-source, real-time, version control platform for startups

Welcome to Sturdy! ?? ?? Real-time code collaboration. Sturdy is an open-source version control platform that allows you to interact with your code at

Dec 24, 2022
Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK)

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Nov 4, 2022
Integrate AWS EKS Anywhere cluster with AWS Services
 Integrate AWS EKS Anywhere cluster with AWS Services

This article provides step-by-step instruction on integrating AWS EKS Anywhere with AWS Services so the applications running on customer data center can securely connect with these services.

Mar 6, 2022
Apis para la administracion de notifiaciones, utilizando servicios como AWS SNS y AWS SQS

notificacion_api Servicio para envío de notificaciónes por difusión en AWS SNS Especificaciones Técnicas Tecnologías Implementadas y Versiones Golang

Jan 7, 2022
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

Dec 20, 2022
A package for access aws service using AWS SDK for Golang

goaws ?? A package for access aws service using AWS SDK for Golang Advantage with goaws package Example for get user list IAM with AWS SDK for Golang

Nov 25, 2021
Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.
Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.

tutor-pet API Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure. Macro architecture: Code architecture: Pre-Re

Aug 17, 2022
Aws-parameter-bulk - Export AWS SSM Parameter Store values in bulk to .env files

aws-parameter-bulk Utility to read parameters from AWS Systems Manager (SSM) Par

Oct 18, 2022
Feb 7, 2022