Created
July 9, 2017 21:14
-
-
Save mr-beerkiss/5f36c58c0dbafe92b042ae37f98f50af to your computer and use it in GitHub Desktop.
Utility to generate meaningful, unique S3 bucket names
This file contains 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
// 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