Skip to content

Instantly share code, notes, and snippets.

View medwig's full-sized avatar

Jonathan Medwig medwig

  • Faire
  • Kitchener, Canada
View GitHub Profile
@medwig
medwig / terraform_echo_workspace.sh
Created December 11, 2019 15:44
Terraform echo workspace before running apply or output command
# Run tf with echo tf-workspace
tf_with_tf_workspace() {
if [[ "$@" == "apply" ]] || [[ "$@" == "output" ]];
then
\terraform workspace list;
fi
\terraform "$@";
}
alias tf="terraform"
@medwig
medwig / list_all_python_requirements_in_repo.sh
Created November 8, 2019 14:22
List all python packages in repo requirements
find -name 'requirements.txt' | xargs cat | sort | uniq > python_packages.txt && sed -i 's/[=<>].*$//g' python_packages.txt && uniq python_packages.txt && pip install -r python_packages.txt && cat python_packages.txt | xargs -d $'\n' sh -c 'for arg do pip show $arg | grep -v -e "^Location:" -e "^Requires:" -e "^Required-by:"; echo; done' > summary_python_packages.txt
@medwig
medwig / download_lambda_function.sh
Created June 26, 2019 12:12
Download AWS lambda function package cli
#!/usr/bin/env bash
# Download AWS lambda function package
# Add to ~/.bashrc
getLambda() {
functionName=$1
awsProfile=${2:-default}
echo "Getting lambda function $functionName on account $awsProfile"
@medwig
medwig / grep_alias_default_options.sh
Last active May 9, 2019 14:45
Alias grep default options
# Grep default options
GREP_OPTIONS='--color=auto --exclude=*.pyc --exclude-dir=.git --exclude-dir *node_modules* --exclude-dir *.serverless* --exclude-dir *.requirements* --exclude-dir *.terraform*'
alias grep="grep $GREP_OPTIONS"
@medwig
medwig / run_most_recently_built_docker_image.sh
Created May 3, 2019 19:08
Run the latest docker image you just built
docker run -it --entrypoint /bin/sh $(docker images --format "{{.ID}}" | head -n 1)
@medwig
medwig / docker_delete_all.sh
Created April 29, 2019 14:11
Docker delete all images and containers alias
alias docker_rm_all_containers="docker ps -aq | xargs docker rm -f"
alias docker_rm_all_images="docker images -q | xargs docker rmi -f"
@medwig
medwig / buildspec-terraform-symlinks.yml
Created April 23, 2019 13:29
Repair symlinks in AWS codepipeline
@medwig
medwig / create_aws_credentials_file.sh
Created April 19, 2019 05:00
Create aws credentials file from session token
PROFILE=foo
ACCOUNT_ID=123456
ROLE=terraform
aws sts assume-role --role-arn arn:aws:iam::$ACCOUNT_ID:role/$ROLE --role-session-name "foo" > token
aws configure --profile $PROFILE set aws_session_token $(jq < token '.Credentials.SessionToken' -r)
aws configure --profile $PROFILE set aws_access_key_id $(jq < token '.Credentials.AccessKeyId' -r)
aws configure --profile $PROFILE set aws_secret_access_key $(jq < token '.Credentials.SecretAccessKey' -r)
@medwig
medwig / delete_new_files.sh
Last active April 19, 2019 00:57
Delete all files created n minutes ago - Linux
find . -type f -cmin -1 # dry run
find . -type f -cmin -1 -delete
@medwig
medwig / codebuild.tf
Created April 16, 2019 00:25
Codebuild terraform module with docker hub image
module "build" {
source = "git::https://github.com/cloudposse/terraform-aws-codebuild.git?ref=master"
privileged_mode = "true"
build_image = "docker.io/medwig/terraform_serverless:latest"
source_location = "https://github.com/your/repo"
source_type = "GITHUB"
}