URL Shortener


A custom serverless private URL shortener based on Amazon S3, AWS Lambda, Amazon CloudFront and API Gateway.

This project started after reading an article on the aws blog about serving redirect urls from an S3 bucket. The author even provided a CloudFormation template pretty sweet 😄.

Since I wanted to learn how to use CDK I decided to use this template and convert it to to a CDK project to do the same with some minor adjustments to suite my needs.

You are welcome to go to the project repository and have a gander.

If you just want to see the url shortener working navigate to the admin page and give it a go.

Note: Currently this is open for everyone and all links expire after 7 days. If it is abused it will be taken down.

A few things to note if you decide to run the project as is.

  • If you have never used AWS CDK before start by going to CDK Workshop and following their guide.
  • You need an AWS Account and update cdk.json with your account ID and all other relevant details.

Architecture and cost considerations

Using a full serverless application has several benefits: the application is natively multi-AZ and automatically scales whether you have one request per month or tens per second.

Now evaluate the cost of the URL Shortener for a simple scenario: You create 1000 short URLs per month and each is viewed by 1000 users – i.e., 1 million requests per month. Here is a cost estimate for the London region split by services:

  • Lambda: 1000 invocation each of less than 1 second – less than $0.003 / month
  • API Gateway: 1000 API calls – less than $0.004 / month
  • S3: storage cost is negligible, cost for 1 million GET is $0.04 / month
  • Amazon CloudFront: bandwidth cost is negligible, cost for 1 million GET is $0.075 / month

The overall cost is less than 12 cents per month, that’s pretty cheap.. 😉

Feedback

If you need to get in touch, you can find details at the bottom of this page. Alternatively, you can comment here or at the project page on GitHub.


See also