Skip to content

Instantly share code, notes, and snippets.

View si3mshady's full-sized avatar
🐍

Elliott Arnold si3mshady

🐍
View GitHub Profile
@si3mshady
si3mshady / remove_unused_sg.py
Created May 29, 2022 21:19
boto3 practice delete sg not attached to EC2 instance
import boto3
REGION = 'us-east-1'
#list all sg - check
#find all attched sg - check
#filter
#delete
ec2 = boto3.client('ec2', region_name=REGION)
@si3mshady
si3mshady / ECS_ROLL_BACK.py
Last active June 8, 2022 05:34
Rollback ECS image when failures are detected
import boto3
REGION = 'us-east-1'
STACK_NAME = "shawshank-redemption"
TABLE_NAME = 'ecs_images'
STABLE_IMAGE_TABLE = 'stable_images'
ecs = boto3.client('ecs', region_name=REGION)
dynamoClient = boto3.client('dynamodb',region_name=REGION)
CLUSTER_NAME = 'ActivePassiveCluster-us-east-1-dev-'
SERVICE_NAME = 'healthCheckService-us-east-1-dev'
@si3mshady
si3mshady / aws-auth-config-map-utility.py
Created June 18, 2022 05:17
generate aws auth configmap manifest that grants IAM users AWS Roles access to Kubernetes Cluster
import yaml, subprocess, json, re, sys
FILE_NAME = 'auth_config.yaml'
KUBERNETES_GROUP = 'system:masters'
cmd = f'kubectl get configmap aws-auth -n kube-system -o yaml > {FILE_NAME}'
MASTER_PARSER = '({["rolearn":"arn]+[:a-z0-9\/\w-]+"[,"\w\/-:{{{]*[-\w}}",:\[]*[\]]*})' #regex101
@si3mshady
si3mshady / Update_AWS_AuthConfig.py
Created July 28, 2022 00:03
Give EKS cluster access to all users in privileged iam group
import boto3, subprocess
KUBERNETES_GROUP = 'system:masters'
CLUSTER_NAME = 'elliotteks'
REGION = 'us-west-2'
iam = boto3.client('iam')
@si3mshady
si3mshady / tf_boilerplate.py
Created July 29, 2022 10:03
Terraform bootstrapper - for modular tf deployments; bootstrap tf module file structure using command line args
import os, sys, subprocess
BOOTSTRAP_FILES = "main.tf outputs.tf providers.tf variables.tf"
def execute_cmd(cmd):
subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True).communicate()
def gen_cmd_string(module,filename):
return f"touch {get_current_directoy()}/{module}/{filename}"
@si3mshady
si3mshady / tag_default_vpc_and_subnets.py
Last active August 1, 2022 12:53
Small Utility Python function to label all default VPCs and Subnets across a set of regions
import boto3
regions = ['us-east-1', 'us-west-1', 'us-west-2']
def get_default_vpc(region='us-east-1'):
vpc_id = [v['VpcId'] for v in boto3.client('ec2',region_name=region).describe_vpcs()['Vpcs'] if v['IsDefault'] == True][0]
return {"type":"vpc","vpc_id": vpc_id}
@si3mshady
si3mshady / get_deployment_manifest.sh
Created August 4, 2022 01:48
Generate k8s deployment manifest files after using helm
for dep in $(kubectl get deployment | awk '{print $1}'); do kubectl get deployment $dep -o yaml > $dep.yml; done
@si3mshady
si3mshady / kubectl_sed_example.sh
Created August 7, 2022 21:58
Small example of how to use sed to replace content in file, using kubectl.
#!/bin/bash
kubectl run nginx --image=nginx && \
kubectl get pod nginx -o yaml | grep -A5 -B9 uid | grep -v uid | grep -v resource | grep -v creation > clean_base_nginx.yml && \
sed -i.tmp 's/nginx/httpd/g' clean_base_nginx.yml && \
kubectl delete pod nginx && \
@si3mshady
si3mshady / error_count_kubectl.awk
Created August 15, 2022 00:08
AWK practice - filter kubectl output to show counts for running, errorImagePull and imagePullBackup
BEGIN {
imagePullBackOff=0
running=0
errorImagePull=0
}
{
@si3mshady
si3mshady / schedule_zoom_meeting.py
Last active August 21, 2022 23:33
Zoom meeting scheduler
import requests, jwt, json, os, time, sys
apikey = os.getenv('ZOOM_KEY')
apisecret = os.getenv('ZOOM_SECRET')
BASE_ZOOM_URL = 'https://api.zoom.us/v2/'
def generate_jwt():
payload = {"iss": apikey,"exp": time.time() + 300}