Setup a Custom URL Shortener in 2 Minutes With Serverless Cloud
Tags: serverless, cloud, urlshortener, tutorial
Published: 2022-03-04 00:42:08

Originally posted at [Serverless](https://www.serverless.com/blog/setup-a-custom-url-shortener-in-2-minutes-with-serverless-cloud)

It’s relatively easy to setup a url shortener these days, but most of what you’ll end up with is a generic short url that doesn’t represent your brand (ie. bit.ly/abc), or an extremely limited branded domain that you’ll end up paying for as your traffic grows.

With [Serverless Cloud](https://serverless.com/cloud), you can provision your own branded URL shortener service, which you can customize later on if you need to. In this short article, we’ll show you how you can do that in just 2 minutes.

## Fork the URL Shortener

Before you begin, you will need to sign up or login into the [Serverless Cloud dashboard](https://cloud.serverless.com). If you are signing up for the first time, you’ll be asked to choose a username that will also act as the organization name for your personal organization. Serverless Cloud is currently in Public Preview and free to use!

After signing up, you should see a list of available applications you can fork right away. Note that you can see all those forkable apps anytime in [the public official Serverless, Inc org](https://cloud.serverless.com).

Click on the **url-shortener** app to fork it into your organization. You will be prompted to rename your forked app, and to enter the required parameters for this app. For the **url-shortener** app, you only need to enter the **ADMIN_PASSWORD** parameter, which sets the admin password for you to log into your url-shortener dashboard.

![Add an admin password to use when you log into your URL shortener dashboard](https://cdn-images-1.medium.com/max/2772/0*ICskVxM_C50shP23.png)

Choose any password you’d like, but make sure you remember it as we’ll need it later. To keep things simple, we’re going to go with just admin. Click Fork and after a few moments you should be redirected to your app view where you can see a single production stage. Click on it to configure a custom domain.

## Configure a Custom Domain

The URL shortener is useless without a short custom domain. If you have a short domain that makes sense for your brand, use that. Otherwise, we recommend you to use the go.yourdomain.com subdomain instead. For the sake of demonstration, we’re use **go.serverless.com**.

Click on the Settings tab in the production stage page, then click on Domains in the left panel, and Add new domain, and enter your domain name. If you are using a subdomain, make sure you enter the entire subdomain (ie. **go.yourdomain.com**)

![Click on the “Add new domain” button to add a domain](https://cdn-images-1.medium.com/max/3998/0*uj1gaErCwPddXjHL.png)

After you add your domain, you should see a verification record that you will need to add to your registrar to verify your domain.

![Copy the verification records to validate your domain](https://cdn-images-1.medium.com/max/3508/0*hW7VMiFf9FZdhXV5.png)

Log into your domain registrar dashboard and copy/paste the **CNAME** record name & value. We are using AWS Route53, and while your registrar could be different, the process will be similar.

![Paste the verification records into your registrar](https://cdn-images-1.medium.com/max/3998/0*3FJWipxqEktGjAnF.png)

It might take a little while for us to pick up the verification DNS record that you just added, so click on refresh every few moments, until you move to the next and final step, which is adding your app’s DNS record.

![Copy your app records to your registrar](https://cdn-images-1.medium.com/max/3544/0*9rqyYo9wgOAISeIx.png)

Add this **CNAME** record to your registrar just like you added the verification record, and again refresh until your domain has a status of “Ready”.

![Your domain setup is now complete](https://cdn-images-1.medium.com/max/3528/0*LSrXWunR6Jj3c_Y6.png)

You’ve now completed the custom domain setup. Give the CDN a few minutes to propagate, and then you should be able to visit your own private url shortener service under your own domain.

## Use the URL Shortener Dashboard

When you forked the app, you were asked to enter an **ADMIN_PASSWORD** parameter. To log into your URL shortener dashboard, you need to enter that same password you’ve set previously. Needless to say, you shouldn’t share this password for anyone except your team. You may change it anytime in the Serverless Cloud dashboard. Once you enter that password, you should see the following screen:

![Your private URL Shortener dashboard](https://cdn-images-1.medium.com/max/3998/0*FgV0rkT7jlA71U13.png)

You can now shorten any URL you want. You also have the option to specify the exact short name you want to use for each URL. If you don’t specify a name, a short name will be automatically generated for you. For example, We can shorten the [Serverless Cloud Docs URL](https://serverless.com/cloud/docs) to `**go.serverless.com/docs**` by specifying the “**docs**” name.

## Use the URL Shortener API

We’ve seen how to shorten URLs using a GUI, but you could also use the same service programmatically and integrate it into your application to rapidly create short urls on demand. All you have to do is just make the following HTTP request, after replacing **go.serverless.com** with the domain or subdomain you’ve set, and passing the admin password, url you want to shorten, and optionally a short name.
{% gist https://gist.github.com/richardgrantserverless/2990ed283d6663d738ea43354751be17.js %}
## Summary

You’ve seen how you can easily set up a url shortener service for your application, configure a custom domain, and start shortening urls both manually and programmatically. A URL shortener is one of many apps you can instantly fork and use with no coding required. You can see a list of all the available apps in [our public organization page](https://cloud.serverless.com/serverless), and you can fork any of them using relatively the same process. If you have any questions, feel free to [reach out to me on twitter](https://twitter.com/eahefnawy).

[S‍ign up for Serverless Cloud](https://cloud.serverless.com/?view=register&utm_source=serverless-blog&utm_medium=blog&utm_campaign=url-shortner)