Skip to content

Instantly share code, notes, and snippets.

@s-maj
s-maj / main.py
Created October 21, 2019 21:37
blueprint group
from sanic import Blueprint
from sanic import Sanic
from sanic.response import text
bp1 = Blueprint('bp1', url_prefix='/bp1')
bp2 = Blueprint('bp2', url_prefix='/bp2')
@bp1.middleware('request')
async def bp1_only_middleware(request):
@s-maj
s-maj / s3_reupload_sse.py
Last active April 9, 2018 15:14
S3 re-uploader (SSE)
from concurrent.futures import ThreadPoolExecutor, as_completed
import boto3
def process_object(bucket, key):
client = boto3.client('s3', region_name='eu-west-1')
response = client.get_object(
Bucket=bucket,
#Prep
provider "aws" {
region = "eu-central-1"
}
resource "random_id" "alarm" {
byte_length = 8
}
#IAM
@s-maj
s-maj / sts_helper.py
Last active July 19, 2017 18:51
STS assume role helper
import configparser
import os
from collections import OrderedDict
from uuid import uuid4
from dateutil import tz
import boto3
class Cli():
def __init__(self):
@s-maj
s-maj / gist:4e7dd5b88a5dedf8902aa02135baee92
Created May 3, 2017 13:22
s3 batch cleaner with versions
from pprint import pprint
import boto3
def batch_delete(bucket, prefix):
s3c = boto3.client('s3')
paginator = s3c.get_paginator('list_object_versions')
response = paginator.paginate(
from pprint import pprint
import boto3
def batch_delete(bucket, prefix):
s3c = boto3.client('s3')
paginator = s3c.get_paginator('list_objects_v2')
response = paginator.paginate(
from datetime import datetime
from time import time
from uuid import uuid4
import botocore
from awacs.aws import Allow, Statement, Principal, Policy
from awacs.sts import AssumeRole
from boto3 import Session
from troposphere import (Ref, Template, Tags)
from troposphere.ec2 import SecurityGroup, SecurityGroupRule
@s-maj
s-maj / palindromic.py
Created September 22, 2016 18:40
Python Test (Palindromic Numbers)
import string
import unittest
class UnitTests(unittest.TestCase):
def test_change_base_too_small(self):
with self.assertRaises(ValueError):
change_base(10, 1)
def test_change_base_too_big(self):