Skip to content

Instantly share code, notes, and snippets.

View DaneTheory's full-sized avatar
🏠
Working from home

Branden Dane DaneTheory

🏠
Working from home
View GitHub Profile
@bennadel
bennadel / get.js
Created March 2, 2015 13:34
Shedding The Monolithic Application With AWS Simple Queue Service (SQS) And Node.js
// Require the demo configuration. This contains settings for this demo, including
// the AWS credentials and target queue settings.
var config = require( "./config.json" );
// Require libraries.
var aws = require( "aws-sdk" );
var Q = require( "q" );
var chalk = require( "chalk" );
// Create an instance of our SQS Client.
@adon-at-work
adon-at-work / multer-to-s3.js
Last active April 3, 2023 18:10
Sample File Upload From Multer to S3
var AWS = require('aws-sdk'),
fs = require('fs');
// http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Credentials_from_Disk
AWS.config.loadFromPath('./aws-config.json');
// assume you already have the S3 Bucket created, and it is called ierg4210-shopxx-photos
var photoBucket = new AWS.S3({params: {Bucket: 'ierg4210-shopxx-photos'}});
function uploadToS3(file, destFileName, callback) {
@matthewdfuller
matthewdfuller / awsDownloadFilesInBucket.js
Created March 20, 2015 19:36
List and download all files in a given S3 bucket
/* Installation:
* npm install aws-sdk
* npm install async
* node awsDownloadFilesInBucket.js
*/
// SETTINGS
var AWS_KEY = '';
var AWS_SECRET = '';
var BUCKET = '';
@jimfdavies
jimfdavies / helpers.sh
Last active November 16, 2021 02:47
AWS CLI helpers
# Security groups that contain 0.0.0.0/0 rules
aws ec2 describe-security-groups --filters Name=ip-permission.cidr,Values=0.0.0.0/0 --output=text | grep SECURITYGROUPS
# Security groups for ElasticSearch
aws ec2 describe-security-groups --filters Name=ip-permission.from-port,Values=9200 --output=text | grep SECURITYGROUPS
# Search last 10,000/1MB of CloudTrail logs for 'AccessDenied' (removed AWS account number from stream name)
aws logs get-log-events --log-group-name CloudTrail/DefaultLogGroup --log-stream-name 000000000000_CloudTrail_eu-west-1 | grep AccessDenied
# Get number of AWS API calls in time period (assumes a Cloudwatch Logs 'catch-all' filter and metric has been created against CloudTrail logs)
@lesposi
lesposi / .awsrc
Last active December 10, 2018 04:57
Shell primitives for AWS
#!/bin/bash
source ./.awssec
#
# Grab local file and put it in $BUCKET/$S3/path/$FILE
#
function s3-put()
{
[[ $@ == "" ]] &&
@dkinzer
dkinzer / aws_utils.sh
Last active December 10, 2018 05:10
Library to help increase ec2 instance root volume size.
#!/usr/bin/env bash
AWS_DEFAULT_ZONE='us-east-1'
aws_status()
{
echo $(aws ec2 describe-instances --instance-ids="$1" | jq -r '.Reservations[0].Instances[0].State.Name')
}
aws_snapshot_status()
@seventhskye
seventhskye / userdata.d.sh
Last active December 10, 2018 05:02
Userdata script to download and execute a set of bash scripts from Amazon S3. Useful if you wanted to have a predefined set of scripts to share amongst EC2 instance, e.g. userdata.
#!/bin/bash -x
# The bucket containing the userdata.d
export USERDATAD_BUCKET=userdata.example.com
# Required to set the endpoint of the aws-cli
export AWS_DEFAULT_REGION=eu-west-1
# Install Prerequisites
yum install -y aws-cli
# Download all .sh scripts from the bucket and pipe to bash
SCRIPTS=$(aws s3 ls s3://$USERDATAD_BUCKET/userdata.d/ | awk '{ print $4 }')
for S in $SCRIPTS; do
@dossy
dossy / aws-snapshot-backup.sh
Created December 31, 2015 03:37
Create snapshots of current EC2 instance's volumes.
#!/bin/bash
if [ -z "$AWS_CREDENTIALS" ]; then
AWS_CREDENTIALS="$HOME/.aws/credentials"
fi
if [ ! -e "$AWS_CREDENTIALS" ]; then
echo "$AWS_CREDENTIALS missing; use 'aws configure'."
exit
fi
@jamsesso
jamsesso / dev-server.js
Last active August 24, 2020 13:27
Webpack dev server with a better proxy (http-proxy-middleware)
var express = require('express');
var path = require('path');
var webpackConfig = require('./webpack.config');
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var proxyMiddleware = require('http-proxy-middleware');
var devConfig = webpackConfig.devServer;
var app = express();
@cgmartin
cgmartin / le-aws-upload-cert.sh
Last active April 30, 2023 13:09
Scripts for manually creating Let's Encrypt certificates for AWS S3/CloudFront
#!/bin/bash
# Usage:
# $ le-aws-upload-cert.sh
echo "Current list of certificates in AWS"
echo "-----------------------------------"
aws iam list-server-certificates
echo
read -p "Domain name: " domain_name