Skip to content

Instantly share code, notes, and snippets.

View jonathanhle's full-sized avatar

Jonathan Le jonathanhle

View GitHub Profile
@jonathanhle
jonathanhle / secretsmanager.tf
Created February 22, 2019 23:14 — forked from anttu/secretsmanager.tf
Terraform AWS Secrets Manager example with key and value
resource "aws_secretsmanager_secret" "IRCSecrets" {
name = "irc/client/credentials"
description = "My IRC client credentials"
}
resource "aws_secretsmanager_secret_version" "IRCCredentials" {
secret_id = "${aws_secretsmanager_secret.IRCSecrets.id}"
secret_string = "{\"username\":\"AzureDiamond\",\"password\":\"hunter2\"}"
}
@jonathanhle
jonathanhle / go-ssh-reverse-tunnel.go
Created March 4, 2019 23:44 — forked from codref/go-ssh-reverse-tunnel.go
Go SSH reverse tunnel implementation (SSH -R)
/*
Go-Language implementation of an SSH Reverse Tunnel, the equivalent of below SSH command:
ssh -R 8080:127.0.0.1:8080 [email protected]
which opens a tunnel between the two endpoints and permit to exchange information on this direction:
server:8080 -----> client:8080
@jonathanhle
jonathanhle / botos3upload.py
Created March 10, 2019 17:01 — forked from SavvyGuard/botos3upload.py
Use boto to upload directory into s3
import boto
import boto.s3
import os.path
import sys
# Fill these in - you get them when you sign up for S3
AWS_ACCESS_KEY_ID = ''
AWS_ACCESS_KEY_SECRET = ''
# Fill in info on data to upload
@jonathanhle
jonathanhle / lambda_assume_role.py
Created March 10, 2019 19:29 — forked from ozgurakan/lambda_assume_role.py
Assume Role within A Lambda function (Python)
import boto3
# you can assign role in the function like below
# ROLE_ARN = 'arn:aws:iam::01234567890:role/my_role'
#
# or you can pass role as an evironment varibale
# ROLE_ARN = os.environ['role_arn']
ROLE_ARN = = os.environ['role_arn']
@jonathanhle
jonathanhle / s3dirupload.py
Last active April 26, 2019 01:47
Upload directory and subdirectories to S3
import argparse
import boto3
import mimetypes
import os
# python3 s3dirupload.py --rolearn "arn:aws:iam::account:role/OrganizationAccountAccessRole" --destinationbucket "bucket" --sourcedirectory '/assets'
# Get CLI Arguments
parser = argparse.ArgumentParser(description='Upload directory to S3.')
parser.add_argument('--sourcedirectory',
@jonathanhle
jonathanhle / upload directory to s3 with terraform local-exec + python
Created March 10, 2019 22:54
upload directory/subdirectories to s3 with terraform local-exec + python
resource "aws_s3_bucket" "foobar_bucket_name" {
bucket = "${var.name_prefix}-foobar-name-${var.env}"
acl = "private"
lifecycle_rule {
id = "${var.name_prefix}-foobar-name-${var.env}-abort-incomplete-multipart"
enabled = true
abort_incomplete_multipart_upload_days = 7
}
@jonathanhle
jonathanhle / tfinstall.sh
Last active May 18, 2019 00:19
osx terraform install
# Example Run: bash tfinstall.sh "0.11.14"
# Example Run with Curl: curl https://gist.githubusercontent.com/jonathanhle/e7cbee565e61d34a57ded7edd6cdad6e/raw/4cf991ccd2ed3ed38bef4bf58dd5bc22bb7c1c8f/tfinstall.sh | bash -s "0.11.14"
export tfversion=$1
# Check if terraform is installed
if which -s terraform
then
echo "Terraform client is already installed":
terraform --version
@jonathanhle
jonathanhle / requests-with-retry.py
Created May 29, 2019 00:40 — forked from benjiao/requests-with-retry.py
Python requests with retry
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
with requests.Session() as s:
retries = Retry(
total=10,
backoff_factor=0.2,
status_forcelist=[500, 502, 503, 504])
@jonathanhle
jonathanhle / zipapp.md
Created June 2, 2019 17:26 — forked from lukassup/zipapp.md
Python zipapp

Python zipapp web apps

What's a zipapp?

This concept is very much like .jar or .war archives in Java.

NOTE: The built .pyz zipapp can run on both Python 2 & 3 but you can only build .pyz zipapps with Python 3.5 or later.

Initial setup

# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
import BaseHTTPServer, SimpleHTTPServer
import ssl