Last active
August 9, 2016 18:21
-
-
Save andsens/5107971 to your computer and use it in GitHub Desktop.
Google spreadsheet function for signing S3 URLs (very handy for CSV cost allocation reports when combined with the ImportData() function)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sign_s3(access_key, private_key, bucket, object_name, validity, base_url) { | |
if(!base_url) { | |
base_url = "http://s3.amazonaws.com"; | |
} | |
if(!validity) { | |
validity = 60; | |
} | |
expires = Math.floor((new Date()).getTime() / 1000) + validity; | |
object_name = encodeURIComponent(object_name); | |
stringToSign = "GET\n\n\n"+expires+"\n/"+bucket+"/"+object_name; | |
signature = encodeURIComponent(Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_1, stringToSign, private_key))); | |
url = base_url+"/"+bucket+"/"+object_name+"?AWSAccessKeyId="+access_key+"&Expires="+expires+"&Signature="+signature; | |
return url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment