Skip to content

Instantly share code, notes, and snippets.

@mr-beerkiss
Created July 9, 2017 21:14
Show Gist options
  • Save mr-beerkiss/5f36c58c0dbafe92b042ae37f98f50af to your computer and use it in GitHub Desktop.
Save mr-beerkiss/5f36c58c0dbafe92b042ae37f98f50af to your computer and use it in GitHub Desktop.
Utility to generate meaningful, unique S3 bucket names
// Requires Node 8
// Usage node index.js your-bucket-name
const promisify = require("util").promisify;
const shasum = require("shasum");
const randomBytes = promisify(require("crypto").randomBytes);
(async () => {
try {
const prefix = "some-appropriate-prefix-";
const desiredName = process.argv[2];
if (!desiredName) throw new Error("You must name your bucket!");
const randBuf = await randomBytes(256);
const hash = shasum(randBuf, "sha256");
console.log(`${prefix}${desiredName}-${hash.substring(0, 6)}`.toLowerCase());
} catch (e) {
console.log("Error thrown generating bucket name", e);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment