Your own custom URL-shortener!
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
index.html is a custom URL-shortener for private use. It is hosted entirely on Amazon AWS and is backend free!

You can download and use this code in order to create your own private URL-shortener!


Admin GUI

Setup your own URL-shortener


  • A custom domain (i.e.
  • Amazon AWS (S3, IAM, Route53, CloudFront optional)
  • Facebook app.
  • A personal Facebook account.

Step 1. Setup S3 bucket

Let's setup an S3 bucket to host our URL-shortener.

  1. Create a S3 bucket in the AWS console, name it the name of your domain, i.e.
  2. Edit the bucket policy to grant s3:GetObject permissions to everyone for the bucket:
  "Version": "2012-10-17",
  "Statement": [
      "Sid": "AddPerm",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      "Action": "s3:GetObject",
      "Resource": "*"
  1. Add CORS configuration to the bucket:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="">
  1. Enable static website hosting on the S3 bucket, and set the Index Document and the Error Document to index.html

Step 2. Setup Route 53

  1. Create a new hosted zone for your domain.
  2. Point your domain nameserver (via your domain providers control panel) to the nameserver provided by Route 53.
  3. Setup an A pointer for your root domain with Alias to point at your bucket, i.e.

Step 3. Setup Facebook application

Now we'll create a facebook application. This will allow you to administer your URL-shortener directly online by logging into Facebook.

  1. Create a new Facebook app (website) on
  2. Set Site URL to your domain, i.e.
  3. In the app settings, set App Domains to your domain, i.e.
  4. Make a note of your Facebook App ID which will be used later, i.e. 602729056487961.
  5. Make a note of your Facebook App Secret, which will be used in the next step.

Step 4. Find your application specific user id

  1. We'll now manually log in to your app. Visit this URL (replace APP_ID and change the redirect_uri to your domain):
  2. After authorizing the app, you'll be redirected to your domain with a code URL parameter, something like:
  3. Extract the code, and now visit (replace parameters with your values):
  4. Save the access_token that you get back.
  5. Visit
  6. Save the ID you get back for later.

Step 5. Configure IAM

Now we'll add a role that will allow only you to modify contents of your S3 bucket after you've logged into Facebook.

  1. In the AWS console, head to IAM and create a new role. Name it anything, I've named mine
  2. Select Role for Identity Provider Access
  3. Select Grant access to web identity providers
  4. Select Identity Provider: Facebook and enter your Facebook application id.
  5. Click Add conditions, make sure Condition is StringEquals and select Key:
  6. Enter your application specific user id that you found in step 3 (not the FB App ID)
  7. After you've saved your condition, continue.
  8. Your Trust Policy Document should now look similiar to mine:
  "Version": "2012-10-17",
  "Statement": [
      "Effect": "Allow",
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Principal": {
        "Federated": ""
      "Condition": {
        "StringEquals": {
          "": "717273996",
          "": "602729056487961"
  1. Save the role and make a note of the Role ARN for later, i.e. arn:aws:iam::507606061091:role/
  2. Add a new inline role policy to the role, I called mine, and give it the following contents:
  "Version": "2012-10-17",
  "Statement": [
      "Sid": "Stmt1391915077000",
      "Effect": "Allow",
      "Action": [
      "Resource": [

Step 6. Configure the admin application

Clone this repo, modify the js/app.js file and upload it to the root of your S3 bucket. The parts that need changing in app.js are:

pekso.service('$config', function() {
    this.fbAppId = '602729056487961';
    this.awsS3Bucket = '';
    this.awsWebIdentityRole = 'arn:aws:iam::507606061091:role/';
    this.awsRegion = 'eu-west-1';
    this.domain = ''; // avoid trailing slash

And you should be done! Head over to your domain, login and shorten some urls! :)


CloudFront configuration.