Skip to content

Instantly share code, notes, and snippets.

@grahamlyons
grahamlyons / account.py
Created November 21, 2019 22:01
Assume a role in an AWS account with Python
import boto3
def assume_role(account_id: str, role_name: str) -> boto3.Session:
sts = boto3.client('sts')
response = sts.assume_role(
RoleArn=f'arn:aws:iam::{account_id}:role/{role_name}',
RoleSessionName='account_creation',
)
return boto3.Session(
@grahamlyons
grahamlyons / apply-trace.output
Created December 21, 2017 12:37
Lambda VPC Panic
2017/12/21 12:35:40 [INFO] Terraform version: 0.11.1 a42fdb08a43c7fabb8898fe8c286b793bbaa4835+CHANGES
2017/12/21 12:35:40 [INFO] Go runtime version: go1.9
2017/12/21 12:35:40 [INFO] CLI args: []string{"/bin/terraform", "apply", "-auto-approve"}
2017/12/21 12:35:40 [DEBUG] Attempting to open CLI config file: /root/.terraformrc
2017/12/21 12:35:40 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2017/12/21 12:35:40 [INFO] CLI command args: []string{"apply", "-auto-approve"}
2017/12/21 12:35:40 [INFO] command: empty terraform config, returning nil
2017/12/21 12:35:40 [DEBUG] command: no data state file found for backend config
2017/12/21 12:35:40 [DEBUG] New state was assigned lineage "eccad70b-25a5-464c-ae79-fcc8e0f8ff7d"
2017/12/21 12:35:40 [INFO] command: backend initialized: <nil>
@grahamlyons
grahamlyons / main.tf
Created June 16, 2017 08:44
Terraform Provisioner
resource "random_id" "id" {
byte_length = 8
provisioner "local-exec" {
command = "./provision.sh ${self.id}"
}
}
@grahamlyons
grahamlyons / README.md
Last active August 7, 2017 09:47
Getting started with RSpec - an example using FizzBuzz

Getting started with RSpec

Assumptions

  • a *nix system
  • Ruby installed - rvm (curl -sSL https://get.rvm.io | bash) is useful for installing the latest version and keeping gems local to your user
  • a directory called workspace in your home directory
  • Atom editor installed - https://atom.io/

First steps

#!/usr/bin/env bash
for file in $(ls *.csv)
do
prefix=$(echo ${file} | cut -d'_' -f1)
echo $prefix
tmpfile=$(tempfile)
while read line
do echo "${prefix},${line}" >> ${tmpfile}
@grahamlyons
grahamlyons / compile.rb
Last active September 11, 2015 10:34
Create two files with Ruby VM bytecode instructions
def get_test_class(a_assignment)
test_class = <<-EOF
class T
attr_accessor(:a)
def initialize
@a = 42
end
def t(this_a=nil)
@grahamlyons
grahamlyons / verisign_certs.sh
Created June 10, 2015 10:53
Add missing Verisign certificates back into CA bundle on CentOS
#!/bin/sh
CERT_PATH=/etc/pki/ca-trust/source/anchors/verisign.crt
write_certs() {
cat > $1 <<EOF
Verisign Class 3 Public Primary Certification Authority
=======================================================
-----BEGIN CERTIFICATE-----
MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMx
@grahamlyons
grahamlyons / gist:1385531
Created November 22, 2011 12:14
Fred's Javascript scoping
function Fred(state){
var innerState = state;
return {
getState: function() {
return innerState;
},
setState: function(newState){
innerState = newState;
@grahamlyons
grahamlyons / .screenrc
Created October 25, 2011 15:35
My screen file
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "
# Map ctrl+\ to screen command key
escape ^\\\
@grahamlyons
grahamlyons / gist:1244613
Created September 27, 2011 08:31
.vimrc and .gvimrc
" .vimrc
set background=dark
set number
set tabstop=4
set shiftwidth=4
set expandtab
syntax on
filetype on
filetype plugin on