Skip to content

Instantly share code, notes, and snippets.

View Burekasim's full-sized avatar

Avi Keinan Burekasim

  • DoiT International
  • Israel
  • 14:22 (UTC +02:00)
View GitHub Profile
@Burekasim
Burekasim / namecode.py
Created April 13, 2020 13:42
Namecode
import pyautogui
from time import sleep
from pynput.mouse import Button, Controller
import random
import string
# generate random file name
def randomString(stringLength=10):
letters = string.ascii_lowercase
from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import random
import string
from time import sleep
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)
@Burekasim
Burekasim / lambda-s3-auto-add-cache-control-header
Created May 13, 2020 17:18
AWS Lamdba python 3.8 script that automatically adds public Cache-Control for 1 year. don't forget to grant iam permission and s3 event trigger.
import json
import boto3
from botocore.exceptions import ClientError
def lambda_handler(event, context):
bucket_name = event['Records'][0]['s3']['bucket']['name']
s3_file = event['Records'][0]['s3']['object']['key']
print(bucket_name, s3_file)
s3 = boto3.client('s3')
@Burekasim
Burekasim / s3-stats.py
Created May 31, 2020 13:44
pulls s3 bucket usage per storage engine
import boto3
from datetime import timedelta, datetime
### Logic:
# this script will list all aws buckets, and will retrieve each bucket size per storage type,
# output will be displayed in mb, if output is 0Mb, the specific storage size is less than 1Mb.
# output will only display used storage types
###
from googletrans import Translator
from urllib.parse import unquote
def lambda_handler(event, context):
data = event['body'].split('&')
body = ''
for item in data:
tt = item.split('=')
if tt[0] == 'Body':
@Burekasim
Burekasim / gke.py
Created June 17, 2020 23:33
GKE api fails with cidr conflict
import string
import random
from google.cloud import container_v1
from google.api_core.retry import Retry
from pprint import pprint
cluster = {
"name": "cluster-" + ''.join(random.choice(string.ascii_lowercase) for i in range(8)),
"master_auth": {
@Burekasim
Burekasim / debug-gcp.py
Created June 21, 2020 14:39
debug with google
def tag_instance(instance: str, project: str, zone: str, creator_email: str):
instance_information = compute.instances().get(project=project, zone=zone, instance=instance).execute()
print(instance_information)
instance_disks_list = [disk['deviceName'] for disk in instance_information['disks']]
instance_fingerprint = instance_information['fingerprint']
print(instance_fingerprint)
instance_labels = {'labels': {'createdby': '123'}, 'labelFingerprint': instance_fingerprint}
print(instance_labels)
request = compute.instances().setLabels(project=project, zone=zone, instance=instance, body=instance_labels)
try:
@Burekasim
Burekasim / debug-gcp.py
Created June 21, 2020 14:39
debug with google
def tag_instance(instance: str, project: str, zone: str, creator_email: str):
instance_information = compute.instances().get(project=project, zone=zone, instance=instance).execute()
print(instance_information)
instance_disks_list = [disk['deviceName'] for disk in instance_information['disks']]
instance_fingerprint = instance_information['fingerprint']
print(instance_fingerprint)
instance_labels = {'labels': {'createdby': '123'}, 'labelFingerprint': instance_fingerprint}
print(instance_labels)
request = compute.instances().setLabels(project=project, zone=zone, instance=instance, body=instance_labels)
try:
@Burekasim
Burekasim / describe_instance.py
Created July 8, 2020 05:46
describe ec2 instance, per aws (cli) profile, per region, print the instance id, instance type and instance state (running/stop/etc) in csv format
import boto3
from pprint import pprint
profiles = ['default']
regions = [region['RegionName'] for region in boto3.client('ec2', region_name='us-east-1').describe_regions()['Regions']]
print('profile,region,instance_id,instance_type,instance_state')
for profile in profiles:
for region in regions:
def lambda_handler(event, context):
host_header = event['Records'][0]['cf']['request']['headers']['host'][0]['value']
new_host_header = host_header.replace('www.', '')
uri_path = event['Records'][0]['cf']['request']['uri']
response = {
'status': '301',
'statusDescription': 'Found',
'headers': {
'location': [{
'key': 'Location',