Created
January 14, 2016 23:00
-
-
Save tomazzaman/83df30dcd1958062f53a to your computer and use it in GitHub Desktop.
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
var crypto = require("crypto"); | |
var SECRET_KEY = 'MY_AWS_SECRET_KEY'; | |
var POLICY_JSON = { | |
"expiration": "2030-12-01T12:00:00.000Z", | |
"conditions": [ | |
{"bucket": "my-bucket-name"}, | |
["starts-with", "$key", ""], | |
{"acl": "public-read"}, | |
["starts-with", "$Content-Type", ""], | |
["content-length-range", 0, 524288000] | |
] | |
}; | |
// No need to edit anything below | |
var encodedPolicy = new Buffer(JSON.stringify(POLICY_JSON)).toString('base64'); | |
console.log("Encoded policy:"); | |
console.log("-------------------------"); | |
console.log(encodedPolicy, "\n"); | |
var signature = crypto.createHmac("sha1", SECRET_KEY).update(encodedPolicy).digest("base64"); | |
console.log("Signature:"); | |
console.log("-------------------------"); | |
console.log(signature, "\n"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple Node.js AWS Policy + Signature generator. Save this file as
policy.js
, modify the two variables according to your needs and settings and finally run this file with Node:$ node policy.js
. All done!