Skip to content

Instantly share code, notes, and snippets.

View atheiman's full-sized avatar
😬

Austin Heiman atheiman

😬
View GitHub Profile
@atheiman
atheiman / cfn-no-resources.yaml
Created October 2, 2020 01:22
CloudFormation template with no resources - useful when generating templates and no resources are added to a template.
Conditions:
Never:
Fn::Equals: [a, b]
Resources:
NullResource:
Type: Custom::Null
Condition: Never
@atheiman
atheiman / Cfn-Stack.yml
Last active November 6, 2024 11:46
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 / User_Data.md
Last active November 15, 2024 09:40
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 February 13, 2025 22:07
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 / README.md
Last active April 5, 2023 13:29
Vault secret saved as file in app pod

These Kubernetes resource manifest yaml files demonstrate

  1. vault.yaml
  • setting up a test vault service
  • configuring the vault service with kubernetes auth and a role for a test app
  1. app.yaml
  • running an app with a vault-init initContainer to login to vault and obtain a token
  • a vault-secret-manager container to continuously interact with vault throughout the lifecycle of the app
  • an app container to use the secret saved by the vault-secret-manager container
# Source: https://gist.github.com/vfarcic/70a14c8f15c7ffa533ea7feb75341545
######################
# Create The Cluster #
######################
# Make sure that you're using eksctl v0.1.5+.
# Follow the instructions from https://github.com/weaveworks/eksctl to intall eksctl.
@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 / include_recipe_spec.rb
Last active November 21, 2017 15:42
Stubbing `include_recipe` while ensuring correct recipes are included. complete example: https://github.com/atheiman/test-cookbook/pull/4
# test_cookbook/recipes/default.rb
include_recipe 'test_cookbook::included_recipe'
include_recipe 'apt'
# test_cookbook/spec/recipes/default_spec.rb
describe 'test_cookbook::default' do
before(:all) { @included_recipes = [] }
before do
@stubbed_recipes = %w[test_cookbook::included_recipe apt]
@atheiman
atheiman / echo_and_run.sh
Created November 3, 2017 20:12
echo_and_run simple shell function to print timestamp and command then execute the command (useful in build tools that dont log well)
$ echo_and_run() { echo "$(date +%T) $*"; $*; }
$ echo_and_run ls
# 15:09:35 ls
# Gemfile Gemfile.lock README.md spec
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}