Skip to content

Instantly share code, notes, and snippets.

View ajbrown's full-sized avatar

A.J. Brown ajbrown

View GitHub Profile
@ajbrown
ajbrown / quartz_jdbc_store.sql
Created December 12, 2013 04:19
The following script creates the schema required to use Postgres as the JDBC store for clustering Quartz. This was tested on Quartz 2.2.1 in Postgres 9.1 and 9.3
CREATE TABLE qrtz_blob_triggers (
trigger_name character varying(80) NOT NULL,
trigger_group character varying(80) NOT NULL,
blob_data text,
sched_name character varying(120) DEFAULT 'TestScheduler'::character varying NOT NULL
);
CREATE TABLE qrtz_calendars (
calendar_name character varying(80) NOT NULL,
calendar text NOT NULL,
@ajbrown
ajbrown / ElasticSearch.template
Created January 15, 2015 21:52
AWS CloudFormation Template For ElasticSearch Cluster
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "ElasticSearch Cluster.",
"Parameters" : {
"KeyName": {
"Description" : "The name of an existing key pair to enable SSH access to Amazon EC2 instances",
"Type": "String",
@ajbrown
ajbrown / letmein.sh
Last active March 19, 2021 07:04
Update a set of security groups, allowing SSH access from your current public IP address.
#!/usr/bin/env bash
#
# Add the security groups you want to allow the current IP address
# SSH access to by updating the "groups" array below. The user
# running the script must have the aws-cli installed and configured.
# Their credentials will be used for API calls, so access should be
# controlled that way.
#
# Note: It's a good idea to clean up these security groups regularly.
# I prefer to have a security group that I can remove all ingress rules
@ajbrown
ajbrown / ASGLeaderDetection.php
Last active January 25, 2021 11:13
Lambda and client code examples for ASG Leader detection. For more info, see https://ajbrown.org/2017/02/10/leader-election-with-aws-auto-scaling-groups.html
<?php
public function isLeader() {
$isLeader = true; // get my instance-id from the metadata service
$instanceId = exec('curl http://169.254.169.254/latest/meta-data/instance-id');
if (!empty($instanceId)) {
$isLeader = false;
$ec2 = \Aws\Ec2\Ec2Client::factory(['key' => AWS_ACCESS_KEY_ID, 'secret' => AWS_SECRET_KEY, 'region' => 'us-east-1']);
$data = $ec2->describeInstances(array('InstanceIds' => [$instanceId]));
if (!empty($data) && !empty($data['Reservations'])) {
$tags = $data['Reservations'][0]['Instances'][0]['Tags'];
@ajbrown
ajbrown / gist:8aea5189d8e84046a4f2
Created March 14, 2016 15:28
BackWPup S3 permissions. This includes the minimum permissions needed to allow the Wordpress BackWPup plugin to complete a backup job with an Amazon S3 destination.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1457967512000",
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets"
],
"Resource": [
@ajbrown
ajbrown / CloudFormation.template
Created June 18, 2015 17:24
CloudWatch mappings of AWS EC2 Instance types to Java Heap sizes
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Use these mappings for cloudwatch templates which launch a java process. They define a heap size close to (but never over) 70% of the available RAM, at multiples of 64 megabytes. No heap is declared over 32GB for performance reasons.",
"Mappings" : {
"AWSInstanceType2JavaMaxHeap" : {
"t1.micro" : { "Heap" : "384m" },
"t2.micro" : { "Heap" : "640m" },
"t2.small" : { "Heap" : "1280m" },
"t2.medium" : { "Heap" : "2816m" },
"t2.large" : { "Heap" : "5g" },
@ajbrown
ajbrown / README.md
Last active March 14, 2018 19:17
EC2 Bootstrapping with AWS CLI Example

This file contains examples of using the AWS CLI to perform bootstrapping actions on EC2 instances through Userdata. These are useful in your terraform scripts to perform configuration that isn't natively supported.

Determine IP Address of EFS mount target

aws efs describe-mount-targets --file-system-id=fs-123456abcd | jq -r '.MountTargets[] | select(.SubnetId | contains("subnet-12345abcd")) | .IpAddress'
@ajbrown
ajbrown / docker-deploy.sh
Last active November 1, 2017 16:31
EC2 Deployment ServiceUpdate
#!/usr/bin/env bash
# Deploy a new image to an ECS service by creating a new task revision
# specifying a container repoository tag, and updating the service to use the new revision.
#
# Note: Your application's container MUST be the first container in the task revision.
#The tag to deploy. Specify as the first cli argument
TAG=$1
@ajbrown
ajbrown / dynamic_java_heap.sh
Created December 17, 2016 17:49
Dynamically determine the Java heap based on the total memory of the VM.
#!/usr/bin/env bash
totalMemKB=$(awk '/MemTotal:/ { print $2 }' /proc/meminfo)
usagePercent=70
let heapMB=$totalMemKB*$usagePercent/100/1024
JAV_OPTS="$JAVA_OPTS -Xmx${heapMB}M -Xms${heapMB}M"

Keybase proof

I hereby claim:

  • I am ajbrown on github.
  • I am adrianjbrown (https://keybase.io/adrianjbrown) on keybase.
  • I have a public key ASASwbI7s2Xh6NiHcNPrdyoRmieDuNC6oSV8Inl8uPMVgwo

To claim this, I am signing this object: