Skip to content

Instantly share code, notes, and snippets.

@davetownsend
davetownsend / buildspec.yml
Last active October 24, 2020 17:27
Get Deploy Role ARN
pre_build:
commands:
- yum install epel-release -y
- yum install jq -y
- param_name=/myapp/$STAGE/deploy_role
- DEPLOY_ROLE=$(aws ssm get-parameter --name $param_name | jq ".Parameter.Value" | tr -d \")
@davetownsend
davetownsend / serverless.yml
Last active August 13, 2019 14:34
iam permissions
functions:
auth:
handler: exampleAuth.verify
iamRoleStatements:
- Effect: Allow
Action: ssm:GetParameters*
Resource: arn:aws:ssm:#{AWS::Region}:#{AWS::AccountId}:parameter/${self:provider.apiname}/${self:provider.stage}/okta/*
- Effect: 'Allow'
Action: 'kms:Decrypt'
Resource: arn:aws:kms:#{AWS::Region}:#{AWS::AccountId}:key/${ssm:/example/${self:provider.stage}/kms/keyid~true}
@davetownsend
davetownsend / authPolicy.js
Created August 13, 2019 00:24
middy config
module.exports.verify = middy(verify).use(
ssm({
cache: true,
cacheExpiryInMillis: 5 * 60 * 1000,
setToContext: true,
names: {
ISSUER: `/example/${stage}/okta/issuer`,
CLIENT_ID: `/example/${stage}/okta/clientid`,
AUDIENCE: `/example/${stage}/okta/audience`
}
@davetownsend
davetownsend / serverless.yml
Created August 13, 2019 00:23
apigw auth config
exampleData:
handler: example.getExample
events:
- http:
path: /${self:provider.apiname}/read
method: get
authorizer:
name: auth
identitySource: method.request.header.Authorization
identityValidationExpression: ^Bearer [-0-9a-zA-z\.]*$
@davetownsend
davetownsend / serverless.yml
Last active August 13, 2019 00:19
auth function config
functions:
auth:
handler: exampleAuth.verify

Keybase proof

I hereby claim:

  • I am davetownsend on github.
  • I am davetownsend (https://keybase.io/davetownsend) on keybase.
  • I have a public key whose fingerprint is 9151 93CF B605 3101 DA87 F75D CCD3 E43A 7A70 A986

To claim this, I am signing this object:

@davetownsend
davetownsend / gist:eb7c241240b1a1f95e9b
Created March 10, 2015 23:02
reload launchd.conf
# run from cli to re-load new enries in lanuchd.conf
grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
@davetownsend
davetownsend / rename.groovy
Created November 26, 2014 15:25
Bulk file re-name with Groovy script
// needed to rename over 900 files in a dir from a pattern like
// noa_6989589000_201404080445010001.pdf to NAR6989589000.pdf where the 6989589000 part
// (different on every file) is the needed in the new file.
// simply run from the CLI: groovy rename.groovy
dir = "/path to files"
def pre = "NAR", ext = ".pdf"
new File(dir).eachFile() { f ->
def name = f.name.split('_')[1]
f.renameTo("${pre}${name}${ext}")
@davetownsend
davetownsend / gist:94bd1cd9165884d9b922
Last active June 29, 2018 05:13
Multiple Ehcache with Spring 4 Java Config
package org.dt.cachetest;
import net.sf.ehcache.config.CacheConfiguration;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@davetownsend
davetownsend / node-and-npm-in-30-seconds.sh
Last active August 29, 2015 14:02
Install Node for zsh users
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.zshrc
. ~/.zshrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl -L https://www.npmjs.com/install.sh | sh