Skip to content

Instantly share code, notes, and snippets.

Working on AWS' cloud

John Preston JohnPreston

Working on AWS' cloud
View GitHub Profile
JohnPreston /
Created Feb 27, 2020
Regexps for CIDR/IP validation (checks it is within 0-255 range)
ipv4_ip = r'((((((([0-9]{1}\.))|([0-9]{2}\.)|(1[0-9]{2}\.)|(2[0-5]{2}\.)))){3})(((((([0-9]{1}))|([0-9]{2})|(1[0-9]{2})|(2[0-5]{2}))))){1,3})'
ipv4_ip_link = ''
ipv4_cidr = r'((((((([0-9]{1}\.))|([0-9]{2}\.)|(1[0-9]{2}\.)|(2[0-5]{2}\.)))){3})(((((([0-9]{1}))|([0-9]{2})|(1[0-9]{2})|(2[0-5]{2}))))){1,3})\/(([0-9])|([1-2][0-9])|((3[0-2])))$'
ipv4_cidr_link = ''
View gist:ebbf8e7499aee697eda207f3f1eee135
#For specific file extension
#For specific file extension or no extension at all
#!/usr/bin/env bash
# creates a new TMUX session and opens windows in predefined folders, and for python, activates virtual environment
tmux new-session -s $session\; \
send-keys 'cd /home/john/work/pe_v2_common' C-m \; \
send-keys 'source .venv/bin/activate' C-m \; \
new-window -t $session:1 \; \
send-keys 'cd /home/john/work/pe_v2_core' C-m\; \
send-keys 'source .venv/bin/activate' C-m \; \
JohnPreston /
Created May 23, 2019
Delete default VPC in all regions
#!/usr/bin/env bash
for region in $(aws ec2 describe-regions --region eu-west-1 | jq -r .Regions[].RegionName); do
echo "* Region ${region}"
# get default vpc
vpc=$(aws ec2 --region ${region} describe-vpcs --filter Name=isDefault,Values=true | jq -r .Vpcs[0].VpcId)
if [ "${vpc}" = "null" ]; then
echo "No default vpc found"
JohnPreston /
Last active Mar 23, 2019
Useful python re regexp for AWS
lambda_layer_pattern = r'(^arn:aws:lambda:[a-z]{2}-[a-z]{1,12}-[0-9]{1}:[0-9]{12}:layer/[a-z]+:[0-9]+$) or (^[a-z]+:[0-9]+$)'
for images in `docker images |grep ecr | awk '{print $3}'`; do docker ps -a |grep $images | awk '{print $1}' | xargs -i -P10 docker rm {} ; docker rmi $images ; done
for map in `sed 's/^ .*//1' $file | sed '/^\s*$/d' | sed 's/\://g'`; do touch "$file"_"$map.yml"; done
View regexes_cheatsheet.txt
AWS ARN TOPIC (py 3.6, re)

Keybase proof

I hereby claim:

  • I am johnpreston on github.
  • I am johnpreston78 ( on keybase.
  • I have a public key whose fingerprint is 5C93 2084 E03F 7DD1 3ED8 16A4 9145 77AC 111D 1F0A

To claim this, I am signing this object:

JohnPreston / addip.service
Created Mar 8, 2017
Systemd call to script to add an IP
View addip.service
Description=Add Secondary IP
You can’t perform that action at this time.