A simple URL shortener API running on NodeJS/Typescript/AWS Lambda/Serverless Framework/DynamoDB.
Original version (see branch) completed in a mad 3-hour dash for a coding exercise, tidied up later. The basic features are
POST /?url={longUrl}
endpoint for creating short URLS- returns short URL if given URL is already shortened
GET /{shortUrl}
endpoint that redirects to given target URL if found- we're keeping track of successful redirects for statistics
GET /{shortUrl}/stats
endpoint that returns hourly redirect counts per givenshortUrl
-
Use an async DynamoDB client to get rid of nested callbacks - Write an OpenAPI schema and use API Gateway to validate requests
- Integration tests: try running integration tests locally against
serverless-offline
andserverless-dynamodb-local
-
Smarter hourly time-series aggregation as opposed to the naive full-table scan - CI/CD: build, run tests and lint on GitHub actions + run
sls deploy
if onmaster
branch -
Set DynamoDB table names as Serverless Framework config variables and pass to Lambda handlers as env vars to avoid hardcoding table names to code - Tune the Lambda IAM policy to avoid overly wide permissions
yarn
- Serverless framework
- Java Runtime Engine (JRE) version 6.x or newer for local DynamoDB
First install dependencies:
yarn install
sls dynamodb install
Then start local development server with sls offline start
.
yarn test
sls deploy