https://github.com/mathisve/serverless-link-shortener
100% serverless link shortener built on AWS Lambda and Upstash
https://github.com/mathisve/serverless-link-shortener
aws lambda redis serverless upstash
Last synced: 12 months ago
JSON representation
100% serverless link shortener built on AWS Lambda and Upstash
- Host: GitHub
- URL: https://github.com/mathisve/serverless-link-shortener
- Owner: mathisve
- Created: 2021-05-14T14:34:05.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-31T22:57:20.000Z (almost 5 years ago)
- Last Synced: 2025-04-06T22:35:07.771Z (12 months ago)
- Topics: aws, lambda, redis, serverless, upstash
- Language: Go
- Homepage: https://youtu.be/EJ6CJ0GC9lk
- Size: 4.9 MB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# serverless-link-shortener

**A stateful serverless API built on top of AWS Lambda and Upstash Redis.**
## Special thanks to [Upstash](https://upstash.com/) for making projects like this possible!
## About:
The codebase consists of 2 functions:
- `new` to add links to the database, returns the shortened hash/code
- `get` to retrieve the links given the hash/code, returns HTML
## Code snippet:
```go
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
// extract hash from API Gateway headers
hash := request.Headers["hash"]
// get from Redis compatible Upstash database
val, err := client.Get(ctx, hash).Result()
if err == redis.Nil {
// hash not found
return Response{
StatusCode: 404,
Body: notFoundResponse,
Headers: headers,
}, nil
}
// did find hash
return Response{
StatusCode: 200,
Body: fmt.Sprintf(redirectResponse, val),
Headers: headers,
}, nil
}
```
## Video:
If you prefer to have me explain it to you, you're in luck!
Watch the video [here](https://youtu.be/EJ6CJ0GC9lk)! (or click the thumbnail!)
[](https://youtu.be/EJ6CJ0GC9lk)