Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Created July 26, 2017 12:58
Show Gist options
  • Save Mikulas/49e69140c5cee104ce3d288931dd16fa to your computer and use it in GitHub Desktop.
Save Mikulas/49e69140c5cee104ce3d288931dd16fa to your computer and use it in GitHub Desktop.
aws vpc flow log analysis with postgres
COPY vpc FROM '/SOME/PATH/concat' WITH (FORMAT CSV, DELIMITER ' ', NULL '-');
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
aws s3 cp --recursive s3://bucket/flow .
for FILE in */*.gz; do
echo "$FILE"
gzip -d "$FILE"
done
if -e concat; then
echo 'concat file already exists'
exit 1
fi
for FILE in */*; do
echo "$FILE"
cat "$FILE" >> concat
rm -rf "$FILE"
done
CREATE TABLE "public"."vpc" (
"time" timestamp NOT NULL,
"version" integer NOT NULL,
"account" text NOT NULL,
"interface" text NOT NULL,
"srcaddr" inet,
"dstaddr" inet,
"srcport" integer,
"dstport" integer,
"protocol" text,
"packets" bigint,
"bytes" bigint,
"start" text,
"end" text,
"action" text,
"log-status" text
) WITH (oids = false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment