Skip to content

Instantly share code, notes, and snippets.

View bushong1's full-sized avatar

Charles Bushong bushong1

View GitHub Profile
@bushong1
bushong1 / handler-bash.sh
Last active October 21, 2020 13:50
Serverless Hello Bash
hello () {
set -e
echo "{\"statusCode\": 200, \"body\": \"Hello, from Bash\"}" >&2
}
@bushong1
bushong1 / essentials.bash
Created May 27, 2019 13:04
bash essentials
# Check for arbitrary environment variables
UNSET_ENVS=false
function check_env() {
if [ -z "${!1}" ]; then
>&2 echo "ERROR: Environment Variable '$1' is not set"
export UNSET_ENVS=true
else
echo "$1 set to ${!1}"
fi
}
@bushong1
bushong1 / aws-ecs-get-docker-version.py
Created February 18, 2019 18:45
Script to fetch current Docker version from all AWS ECS instances
#!/usr/bin/env python3
import boto3
import sys
import re
ecs = boto3.client('ecs')
sys.argv.pop(0)
clusters=[]+sys.argv
if len(clusters) == 0:
@bushong1
bushong1 / gist:c56c8ffece4132b3b31db54ea5e03ac2
Created February 1, 2019 17:23
Cloudwatch Logs Agent ecs-agent logs
[general]
state_file = /var/awslogs/state/agent-state
[/var/log/ecs/ecs-agent.log]
file = /var/log/ecs/ecs-agent.log.*
log_group_name = MyCoolEnvironment-ecs
log_stream_name = ecs-agent/`curl http://169.254.169.254/latest/meta-data/instance-id`
datetime_format = %Y-%m-%dT%H:%M:%SZ
@bushong1
bushong1 / update-gemfile-lock.sh
Last active August 22, 2018 15:12
Update Gemfile.lock using Docker without Ruby installed locally
#!/bin/bash
if [ ! -f ./Gemfile.lock ]; then
# No Gemfile.lock present, create a new one
touch Gemfile.lock
fi
if [ -f ./.ruby-version ]; then
ruby_version="$(cat .ruby-version)"
else
ruby_version="latest"
fi
@bushong1
bushong1 / gist:9754c2ad9ed4c0348436252a1e8cc04d
Created August 13, 2018 19:16
Wrapper for awslogs to simplify prod vs nonprod
function app-logs() {
if [ -z $1 ] || [ -z $2 ]; then
echo "usage: app-logs <env> <service> [<awslogs params>]"
return 1
fi
if [ "$1" = "production" ] || [ "$1" = "staging" ]; then
ACCOUNT=prod
else
ACCOUNT=default
fi
ARG MY_ARG
RUN : "${MY_ARG:?ERROR - MY_ARG Build argument needs to be set and non-empty.}"
@bushong1
bushong1 / entrypoint.sh
Created July 26, 2018 13:13
Docker Entrypoint to pull in ParameterStore variables and S3 Buckets
#!/bin/bash -e
# Usage:
# 1) Build the AWS CLI into your container
# 2) Set your region, or pass env into the container
export AWS_DEFAULT_REGION=us-east-1
function usage () {
echo "Usage: Container must be run with the following environment variables:
@bushong1
bushong1 / centos-7-user-data.yml
Last active January 22, 2018 18:25
A gist to run a dockerize papertrail container for reporting ECS container logs
Parameters:
PapertrailEndpoint:
Type: String
Default: logsX.papertrailapp.com:XXXXX
Resources:
LaunchConfig:
Properties:
...
UserData:
Fn::Base64: !Sub |
@bushong1
bushong1 / .bashrc
Created November 17, 2017 14:18
A BASH function to shortcut removing an AMI and it's associated Snapshots
function aws-rm-ami-snap() {
if [[ ${1} == ami-* ]]; then
AMI_ID=${1}
SNAPSHOT_IDS=$(aws ec2 describe-images --filters Name=image-id,Values=${1} | jq '.Images[].BlockDeviceMappings[].Ebs.SnapshotId' | sed 's/"//g')
aws ec2 deregister-image --image-id ${AMI_ID}
for snapshot_id in ${SNAPSHOT_IDS}; do
aws ec2 delete-snapshot --snapshot-id ${snapshot_id}
done
else
echo "ERROR: Require \$1 to be an AMI ID, starting with 'ami-'"