One-Click Generate & Copy Unique Names / UUIDs for Your Cloud Resources

If you spend a lot of time managing cloud infrastructure manually via the cloud provider’s web console, you often need to come up with unique names for your cloud resources. You probably have a naming convention in place for most cloud services that you work with, but when it comes to global services like Amazon S3, you must resort to unique alpha-numeric “generated” identifier strings for at least a portion of the resource name. This article provides a one-click generate & copy solution for such names. All you have to do is click & paste!

The idea is to place a bookmarklet in your browser’s bookmarks bar that contains a piece of JavaScript code that both generates the name & copies it to your clipboard so you can paste it right away. Here’s the code we’ll use:

javascript: (function () {
    function uuidv4() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }

    function copy(text) {
        var input = document.createElement('input');
        input.style.position = 'fixed';
        input.style.opacity = 0;
        input.value = text;
        document.body.appendChild(input);
        input.select();
        document.execCommand('copy');
        document.body.removeChild(input);
    }

    var prefix = 'prefix';
    var suffix = 'suffix';
    copy(prefix + '-' + uuidv4() + '-' + suffix);
})()

This code generates a UUID, adds a prefix & suffix to it, & copies it to the clipboard. Here’s a sample:

prefix-c6319798-f8ef-49f6-9899-6342287b87c9-suffix

You can change or remove the prefix and/or suffix, or if you don’t need the entire UUID, just use a portion of it. Once you have the script ready, create a new bookmark in your browser & paste in the JavaScript code. Now, whenever you need a unique name, just click the bookmarklet & paste the name.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.