Need help with serverless-url-shortener?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

155 Stars 42 Forks MIT License 60 Commits 11 Opened issues


URL shortener for AWS Lambda and S3

Services available


Need anything else?

Contributors list

# 207,812
47 commits
# 100,293
9 commits
# 376,419
2 commits

Serverless URL Shortener

A lightweight URL shortener built with the Serverless Framework using AWS Lambda and S3. Each URL redirection is stored as an S3 object with the

metadata key set to the forwarding web address. AWS Lambda is used to create an API to save these objects. The website is served from the same S3 bucket.



Install dependencies

Head on over to the Serverless Framework docs and run through their quick-start guide. It’s mentioned in there as part of your setup, but be sure to install the AWS CLI and configure your AWS credentials. Then run

npm install
to get the NPM dependencies for the project.

Setup Route 53

Create Route 53 hosted zones for both the API and website.

Add environment variables

Create a copy of .env.example for each "stage" that you wish to deploy to (e.g .env.staging, .env.production) and then customise each configuration file as appropriate for your setup.

| Name | Description | Required | | -------------------- | ------------------------------------------------------------ | -------- | | BUCKET | S3 bucket that will store URL redirects | Y | | REGION | AWS region to deploy to | Y | | APIURL | API endpoint the website will interact with | Y | | APIDOMAIN | Custom API domain the API will be served from | Y | | APIHOSTEDZONE | AWS Route53 hosted zone ID with the custom API domain | Y | | APICERTIFICATENAME | AWS Certificate Authority certificate name for API domain | Y | | APIBASEENDPOINT | API Gateway base path (e.g. prefix) for lambda function | Y | | SHORTURL | Base URL of shortened links (without trailing slash) | Y | | SHORTDOMAIN | Custom short domain to serve the website | Y | | SHORTHOSTEDZONE | AWS Route53 hosted zone ID with the custom short domain | Y | | SHORTDOMAINACMARN | AWS Certificate Authority certificate name for short domain | Y | | TITLE | Customize the title of the website and form | N | | CREDIT | Customize the credit name in the footer | N | | CREDITURL | Customize the credit link in the footer | N | | AWS_PROFILE | AWS profile setup in

| N |

Deploy API


npm run deploy
to deploy the API and website to AWS. The resources defined in serverless.yml will be automatically instantiated using CloudFormation. Prefix with the stage you want to deploy (e.g.
STAGE=production npm run deploy

Architecture based on serverless-aws-static-websites:


Build template


npm run build
to build the template with appropriate template variables.

Deploy website


npm run deploy:client
to deploy the website using the AWS CLI.

You can add a

query string parameter to the homepage to specify a vanity (custom) shortcode instead of a randomly-generated one. If the name is already taken, a random one will be used instead.

Libraries used

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.