Skip to content

Instantly share code, notes, and snippets.

@benjaminjbachman
benjaminjbachman / short_s3_presigned_url.py
Created March 16, 2021 17:25
Generates a shorter, older-style s3 presigned url. Can only be used in older regions.
import base64, hmac, os, hashlib, sys, time, urllib
def get_shorter_presigned_url(bucket, key, seconds_alive=600, aws_access_key_id = os.environ.get("AWS_ACCESS_KEY_ID"), aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY"), aws_region = os.environ.get("AWS_DEFAULT_REGION")):
"""
based on https://gist.github.com/mdwhatcott/df9bf33cf044b7352e18
but updated some outdate libraries and added functionality for other regions
no leading '/' on key
eg get_shorter_presigned_url("my-bucket", "some/file.txt")