Skip to content

bskim45/s3-url-shortener

Repository files navigation

s3-url-shortener

Docker Stars Docker Pulls

Super simple flask-based URL shortener leveraging AWS S3

Background

For the full serverless solution, refer to Build a Serverless, Private URL Shortener | AWS Compute Blog

I hate API Gateway (you know, it's expensive)

Architecture

App(flask) -> S3 Redirect(with a optional custom domain) -> Target Site

Requirements

  • Python 3.6 or above
  • S3 Bucket(optionally custom domain)

Prerequisites

Thanks to boto3, all options for providing credentions in boto3 document is good enough.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:ListBucket",
        "s3:PutObjectAcl"
      ],
      "Resource": [
        "arn:aws:s3:::your_s3_bucket",
        "arn:aws:s3:::your_s3_bucket/*"
      ]
    }
  ]
}

Configuration

ENV Default Required Example
PORT 5000 8080
S3_REGION us-east-1 Yes us-east-1
S3_BUCKET Yes hello-bucket
SHORT_DOMAIN https://example.com

Deploy

Old Skool Way

Clone and install requirements:

$ pip install -r requirements.txt

Configure env:

$ cp .env.example .env
$ vi .env

Run app:

$ python run.py

docker-compose

$ cp docker-compose-prod.yaml docker-compose.yaml
# fill in ENV values
$ vi docker-compose.yaml
# run
$ docker-compose up -d

Helm chart

Check out helm-git plugin if you don't want to clone entire repository

$ helm install --name my-release -f values.yaml deploy/charts/s3-url-shortener

Inspired by

License

MIT licensed. See LICENSE for full details.