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 Website-Redirect-Location
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.
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.
Create a copy of config.sample.json as config.json and then customise as appropriate for your setup.
Name | Description | Required |
---|---|---|
BUCKET | The S3 bucket name to use. This will form part of the URL shortener website address if you're not using a custom domain. | Y |
REGION | The AWS region to deploy to. | Y |
STAGE | The AWS stage to deploy to. | Y |
API_URL | The URL of the endpoint that forms should be sent to. This is only known after the first deployment, so leave empty for now. | Y |
Run npm run deploy:serverless
to deploy the API to AWS. The resources defined in serverless.yml will be automatically instantiated using CloudFormation. You should copy the URL of the returned endpoint to API_URL in config.json.
Run npm run build
to set the form action on the website template to API_URL from config.json.
Run npm run deploy:static
to deploy the website using the AWS CLI.
- Serverless Framework for project structure and deployment.
- PaperCSS Framework for the frontend design.
- jQuery to simplify working with the DOM and making AJAX queries.