Skip to content

Instantly share code, notes, and snippets.

View atheiman's full-sized avatar
😬

Austin Heiman atheiman

😬
View GitHub Profile
@atheiman
atheiman / template.yml
Last active March 30, 2024 05:09
CloudFormation template to create a CodeCommit repo and CodeBuild CI/CD. Updates to the main branch and pull requests trigger builds. Feature branch build status is commented on pull requests.
# Usage examples:
#
# Create a new CodeCommit repository with CodeBuild CI/CD
#
# aws cloudformation deploy \
# --stack-name my-new-project \
# --template-file ./template.yml \
# --capabilities CAPABILITY_IAM \
# --parameter-overrides 'RepositoryDescription=My new project description'
#
@mrchief
mrchief / LICENSE.md
Last active March 23, 2024 12:28
Add "Open with Sublime Text 2" to Windows Explorer Context Menu (including folders)

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@atheiman
atheiman / User_Data.md
Last active March 21, 2024 21:15
EC2 User Data examples for Windows and Linux

EC2 User Data examples

Basic Windows local user with Administrator and RDP access

Add a local rdp user via user data at launch of a Windows EC2 instance. Note that this includes a password passed in thru both the user data and powershell command line and is a bad security practice because they can be viewed later. At a minimum, you should connect to the instance immediately after launch and change the password interactively. Also, delete the userdata from the instance after launch. More secure would be to connect the instance to a domain for authentication or use AWS native tooling to connect to the instance (e.g., AWS Session Manager).

<powershell>
# Be sure to set the username and password on these two lines. Of course this is not a good
# security practice to include a password at command line.
@gene1wood
gene1wood / aws-lambda-relative-import-no-known-parent-package.md
Last active March 15, 2024 14:13
Python relative imports in AWS Lambda fail with `attempted relative import with no known parent package`

Python relative imports in AWS Lambda fail with attempted relative import with no known parent package

The Problem

In AWS Lambda if I attempt an explicit relative import like this

.
├── lambda_file.py
└── example.py
@atheiman
atheiman / logging.sh
Created June 6, 2016 21:12
simple shell script logging utility - logging.sh
#!/bin/bash
# Prints all arguments passed to the function with a timestamp prepended. `LOG_DATE_STRING` can be
# overridden by exporting the var. Prepend to the log using `LOG_LEVEL`.
log() {
[[ -z "$LOG_LEVEL" ]] && log_str='' || log_str="$LOG_LEVEL "
log_str="${log_str}$(date "+${LOG_DATE_STRING-%Y-%m-%d %H:%M:%S}") $@"
echo "$log_str"
}
info() { LOG_LEVEL='INFO' log "$@"; }
gfixup() {
set -x
git add --all
git commit --fixup=$(git log --oneline | head -1 | cut -d ' ' -f 1)
git rebase --interactive HEAD~2 --autosquash
set +x
local branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
@atheiman
atheiman / docker_run_nginx.sh
Last active February 11, 2024 01:28
Run nginx in docker container to serve PWD
# Run nginx docker container in background
docker run --name nginx --rm -d -p 8080:80 -v ${PWD}:/usr/share/nginx/html:ro nginx
# Load a file in curent directory
curl http://localhost:8080/index.html
# Stop the docker container (the container will be removed / cleaned up)
docker stop nginx
@atheiman
atheiman / Cfn-Stack.yml
Last active February 11, 2024 01:26
Run command across accounts and regions with SSM
AWSTemplateFormatVersion: '2010-09-09'
Description: >
SSM Automation Document run a custom SSM Command Document
against a fleet of target instances.
Parameters:
AutomationDocumentName:
Type: String
Description: Name of created SSM Automation Document
Default: MyAutomation
@atheiman
atheiman / openssl-create-ca-and-server-cert.sh
Last active February 11, 2024 01:25
Generate a CA cert and private key, then issue a cert to a server
#!/bin/sh
set -eux
CA_FILE_PREFIX="${CA_FILE_PREFIX:-"example-corp-ca"}"
CA_CN="${CA_CN:-"Example Corp CA"}"
CA_SUBJ="${CA_SUBJ:-"/C=US/O=Example Corp/CN=${CA_CN}"}"
SERVER_CN="${SERVER_CN:-"server.example.com"}"
SERVER_FILE_PREFIX="${SERVER_FILE_PREFIX:-"${SERVER_CN}"}"
SERVER_SUBJ="${SERVER_SUBJ:-"/C=US/O=Example Corp/CN=${SERVER_CN}"}"
@atheiman
atheiman / gnu_parallel.sh
Last active February 11, 2024 01:24
GNU Parallel install and usage notes
# Install GNU parallel in a CentOS-based docker container (e.g. for CI/CD)
# install needed dependencies
yum install -q -y bzip2 tar make perl
# download source
curl -s -L -o /tmp/parallel.tar.bz2 https://ftpmirror.gnu.org/parallel/parallel-latest.tar.bz2
# extract source
tar -C /tmp -xjf /tmp/parallel.tar.bz2
# navigate into extracted source
cd /tmp/parallel-*
# build and install