Use case
In cases where some large documents need be shared to client with URLs, these URLs are often lengthy, and use of free online URL shortener services like Bitly.com are prohibited due to confidentiality of documents. As such, I have designed a URL shortener with AWS to solve this problem for myself and team.
Link to demo URL Shortener
The following image shows the webpage of the URL shortener.
Features
- Provides a simple web interface for users to submit long URLs and receive shortened versions of it
- Generate customizable short URLs in the format: http://xxxxx.xxx/h2so4
- Each short URL expires after 10 minutes after creation/accessed
- Displays a custom error page for non-existing short URLs
Solution Component
AWS services
Amazon API Gateway
Amazon CloudFront
Amazon DynamoDB
Amazon EventBridge
Amazon S3
AWS CloudFormation
AWS Lambda
AWS WAF (Optional)
Others
Git
GitHub Actions
Python
HTML
CSS
Solution Overview
The core idea of this solution is using S3 as a redirection engine to redirect URLs based on the attached metadata. When the user enters a short URL, S3 automatically responds with a HTTP redirect to the long URL, see here )for more details.
However, the user need a way to interact with the S3 redirection engine. As such, a website that provide interactions based on client is needed. This is where our API gateway comes into the picture, which will be acting as a simple page for our users and allow them to submit request that will invoke our backend (Lambda functions) to store our shortened URLs into our S3 bucket.
Lastly, we will use Amazon CloudFront to wrap everything together with a simple domain name.
The following diagram depicts the architecture of this solution.
Deployment
For easiest deployment, you can just use the CloudFormation stack provided here to quickly launch all resources in your AWS account.
If you wish to set this up together with a CI/CD pipeline using GitHub actions, please refer to the README in my repo.
Cost
Assumptions: 100 short urls created per month, each viewed by 100 users. So 100x100 = 10,000 requests/month.
Monthly cost: 0.95 USD (without WAF) Yearly cost: 11.4 USD
No upfront cost.
Detailed estimation link: https://calculator.aws/#/estimate?id=0c0cd81bd97e9e112e7ddee985b873c0c34e0ef5
Limitations
Limitations on concurrent users
The limitation is 1,000 concurrent users with the current proposed setup. The bottleneck is Lambda, which is supporting only 1,000 concurrent concurrent executions with the defualt quota.
Scaling strategies
The URL Shortener scales well with the proposed fully serverless architecutre. However, to support more than 1,000 concurrent users, the default quota of Lambda it must be increased by Requesting a quota increase.
Potential Improvements
- Redirect uesr back to homepage if a the link is invalid.
- Setup custom DNS domain name to create a really short URL instead of using cloudfront domain.
- Setup mechanisms like Captcha to deter bot attacks and spam on the service.
- Setup access control such as Cognito to the portal for secure authentication.
- Implement loggings such as CloudWatch to track usage and errors.
- Setup unit tests in the CI/CD pipeline.
Reference
https://aws.amazon.com/blogs/compute/build-a-serverless-private-url-shortener/
Top comments (0)