Skip to content

Instantly share code, notes, and snippets.

View johndstein's full-sized avatar

John Stein johndstein

View GitHub Profile
#!/usr/bin/env bash
# minimum size to get benefit from AWS S3 intelligent tiering.
size=128000
function help() {
echo ""
echo "Usage: s3-stats.sh (options)"
echo ""
echo " Get counts and percent of files over a given size."
@johndstein
johndstein / list-empty-buckets.sh
Created May 20, 2022 11:02
find empty s3 buckets
#!/usr/bin/env bash
# list empty buckets
buckets=$(aws s3api list-buckets| jq --raw-output '.Buckets[].Name')
for bucket in $buckets;do
files=$(aws s3 ls $bucket)
if [[ -z "$myVar" ]]; then
echo "$bucket"
fi
done
@johndstein
johndstein / s3select.sh
Created October 28, 2020 12:19
parallel s3 select
#!/usr/bin/env bash
help () {
echo "
Usage:
test/s3select.sh -v \\
--bucket some-bucket \\
--prefix foo/2020/10/20/20/57 \\
--expression \"select * from s3object o where o.rawmsghostname = 'ynthtest-Oct20T20-filler-5b45a8d7'\"
mongo --ssl \
--host $(cat ~/infrastructure/keys/varsdb-creds | cut -d ':' -f2 | cut -d '@' -f2):27017 \
--sslCAFile /opt/helix-tools/rds-combined-ca-bundle.pem \
--username $(cat ~/infrastructure/keys/varsdb-creds | cut -d ':' -f1) \
--password $(cat ~/infrastructure/keys/varsdb-creds | cut -d ':' -f2 | cut -d '@' -f1)
@johndstein
johndstein / ssjl.js
Created October 10, 2019 18:20
super simple json log for fe
#!/usr/bin/env node
'use strict';
class Log {
constructor(options) {
options = options || {};
this.level = 'off';
this.levels = {
debug: 0,
info: 1,
warn: 2,
@johndstein
johndstein / conditional-pipe.js
Created October 10, 2019 15:20
Solid Gold!!!
#!/usr/bin/env node
'use strict';
const AWS = require('aws-sdk');
if (process.env.AWS_PROFILE) { // eslint-disable-line
AWS.config.credentials = new AWS.SharedIniFileCredentials({
profile: process.env.AWS_PROFILE // eslint-disable-line
});
AWS.config.logger = console;
}
const s3opts = {};
@johndstein
johndstein / s3-jsonl-reader.js
Created October 7, 2019 15:13
S3 JSON line reader (fast / parallel)
#!/usr/bin/env node
'use strict';
const AWS = require('aws-sdk');
if (process.env.AWS_PROFILE) { // eslint-disable-line
AWS.config.credentials = new AWS.SharedIniFileCredentials({
profile: process.env.AWS_PROFILE // eslint-disable-line
});
AWS.config.logger = console;
}
const s3opts = { apiVersion: '2006-03-01' };
@johndstein
johndstein / s3-jsonl-reader.js
Created October 7, 2019 15:13
S3 JSON line reader (fast / parallel)
#!/usr/bin/env node
'use strict';
const AWS = require('aws-sdk');
if (process.env.AWS_PROFILE) { // eslint-disable-line
AWS.config.credentials = new AWS.SharedIniFileCredentials({
profile: process.env.AWS_PROFILE // eslint-disable-line
});
AWS.config.logger = console;
}
const s3opts = { apiVersion: '2006-03-01' };
@johndstein
johndstein / s3-jsonl-reader.js
Created October 7, 2019 15:11
S3 JSON line Reader (slow)
#!/usr/bin/env node
'use strict';
const AWS = require('aws-sdk');
if (process.env.AWS_PROFILE) { // eslint-disable-line
AWS.config.credentials = new AWS.SharedIniFileCredentials({
profile: process.env.AWS_PROFILE // eslint-disable-line
});
}
const s3opts = { apiVersion: '2006-03-01' };
if (process.env.AWS_S3_ENDPOINT) { // eslint-disable-line
@johndstein
johndstein / s3-file-list.js
Created September 24, 2019 14:18
Lambda for listing s3 files
const AWS = require('aws-sdk')
if (process.env.AWS_PROFILE) { // eslint-disable-line
AWS.config.credentials = new AWS.SharedIniFileCredentials({
profile: process.env.AWS_PROFILE // eslint-disable-line
})
AWS.config.logger = console
}
const s3 = new AWS.S3({ apiVersion: '2006-03-01' })
exports.handler = async(event, context) => {
const objects = await s3.listObjects(event).promise();