Skip to content

Instantly share code, notes, and snippets.

@Kaspej
Kaspej / README.md
Created September 13, 2018 16:05 — forked from iMilnb/README.md
AWS Terraform configuration: Stream CloudWatch Logs to ElasticSearch

Rationale

This snippet is a sample showing how to implement CloudWatch Logs streaming to ElasticSearch using terraform. I wrote this gist because I didn't found a clear, end-to-end example on how to achieve this task. In particular, I understood the resource "aws_lambda_permission" "cloudwatch_allow" part by reading a couple of bug reports plus this stackoverflow post.

The js file is actually the Lambda function automatically created by AWS when creating this pipeline through the web console. I only added a endpoint variable handling so it is configurable from terraform.

# Parse url in shell script
# reference: https://stackoverflow.com/a/41161570
function parse_url() {
local query1 query2 path1 path2
# extract the protocol
local proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
if [[ ! -z $proto ]] ; then