Skip to content

Instantly share code, notes, and snippets.

@tomazzaman
Created January 14, 2016 23:00
Show Gist options
  • Save tomazzaman/83df30dcd1958062f53a to your computer and use it in GitHub Desktop.
Save tomazzaman/83df30dcd1958062f53a to your computer and use it in GitHub Desktop.
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");
@tomazzaman
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment