Skip to content

Instantly share code, notes, and snippets.

View JohnPreston's full-sized avatar
🏠
Working on AWS' cloud

John Mille JohnPreston

🏠
Working on AWS' cloud
View GitHub Profile
VERSION=7.3.2;
for REPO_NAME in `aws --region us-east-1 ecr-public describe-repositories | jq -r .repositories[].repositoryName | grep confluentinc`; do
docker pull $REPO_NAME:$VERSION;
docker tag $REPO_NAME:$VERSION public.ecr.aws/ews-network/$REPO_NAME:$VERSION;
docker push public.ecr.aws/ews-network/$REPO_NAME:$VERSION;
done
for REPO_NAME in `aws --region us-east-1 ecr-public describe-repositories | jq -r .repositories[].repositoryName | grep confluentinc`; do
docker rmi public.ecr.aws/ews-network/$REPO_NAME:$VERSION;
docker rmi $REPO_NAME:$VERSION;
ARG BASE_IMAGE=public.ecr.aws/amazoncorretto/amazoncorretto:11
ARG CONNECT_IMAGE=public.ecr.aws/ews-network/confluentinc/cp-server-connect:7.2.1
FROM $BASE_IMAGE as certbuild
ADD https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem /etc/ssl/certs/rds-combined-ca-bundle.pem
ADD https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /etc/ssl/certs/aws-global.pem
RUN yum install perl openssl gawk -y
RUN awk 'split_after == 1 {n++;split_after=0} /-----END CERTIFICATE-----/ {split_after=1}{print > "rds-ca-" n ".pem"}' < /etc/ssl/certs/rds-combined-ca-bundle.pem; \
for CERT in rds-ca-*; do alias=$(openssl x509 -noout -text -in $CERT | perl -ne 'next unless /Subject:/; s/.*(CN=|CN = )//; print') ; echo "Importing $alias" ; keytool -import -file ${CERT} -alias "${alias}" -storepass changeit -keystore /var/opt/aws-rds.jks -noprompt ; done; \
awk 'split_after == 1 {n++;split_after=0} /-----END CERTIFICATE-----/ {split_after=1}{print > "rds-ca-" n ".pem"}' < /etc/ssl/certs/aws-global.pem
@JohnPreston
JohnPreston / changelog.sh
Created May 13, 2021 09:02
Changelog from GIT log
#!/usr/bin/env bash
git log --format="* %h %s (%aN)"
@JohnPreston
JohnPreston / sample_payload.json
Created December 8, 2020 10:32
Sample Payload from GitHub WebHook
{
"after":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
"before":"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a",
"commits":[
{
"added":[
],
"author":{
"email":"lolwut@noway.biz",
@JohnPreston
JohnPreston / CIDR_regexps.py
Created February 27, 2020 11:53
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 = 'https://regex101.com/r/vIL3oX/3'
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 = 'https://regex101.com/r/vIL3oX/4'
#For specific file extension
(^(s3:\/\/)([a-z0-9.-]+)(\/+)?(\/[a-zA-Z0-9.-_\/]+(\/)?)?(\/)([\w-_.]+.sql))
#For specific file extension or no extension at all
(^(s3:\/\/)([a-z0-9.-]+)(\/+)?(\/[a-zA-Z0-9.-_\/]+(\/)?)?(\/)([\w-_.]+)(.zip)?)
#!/usr/bin/env bash
# creates a new TMUX session and opens windows in predefined folders, and for python, activates virtual environment
session=v2
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
JohnPreston / aws_delete_default_vpc.sh
Created May 23, 2019 08:13
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
JohnPreston / AWS_regexps.py
Last active March 23, 2019 19:01
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