Created
July 26, 2017 12:58
-
-
Save Mikulas/49e69140c5cee104ce3d288931dd16fa to your computer and use it in GitHub Desktop.
aws vpc flow log analysis with postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COPY vpc FROM '/SOME/PATH/concat' WITH (FORMAT CSV, DELIMITER ' ', NULL '-'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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