Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

serverless url-shortener

NotificationsYou must be signed in to change notification settings

zoph-io/url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 Rationale

Thisyet another url-shortener, is the one I'm using forAWS Security Digest Newsletter to track click rate from my readers.

I wasn't able to find an existing solution that match my needs so I crafted my own version, another excuse to learn something new 🤓.

Try out this AWS serverless url-shortener for your own usage and see the benefits it can bring.

It's perfect for shortening links and tracking analytics.

Plus, contributions and pull requests are welcome.

💡 Features

  1. Create API
  2. Companion static website (HTML + Javascript)
  3. Hits counter + Analytics (Persisted in DynamoDB)

🔋 Powered by

  • Lambda function (Python 🐍) + API Gateway
  • CloudFront + S3 + ACM
  • DynamoDB Table
  • CloudFormation + SAM

📐 Schema

Architecture Schema

🚀 Usage

Pre-requirements

  1. You will need to have an already issued AWS Certificate Manage (ACM) wildcard Certificate inus-east-1 AWS region:*.{your_domain}
  2. Configure the proper parameters in theMakefile like the Route53 hosted zone Id (HostedZoneId)

🎛 Parameters

ParametersDefault ValueDescription
Producturl-shortenerProduct Name
ProjectzophioProject Name
EnvironmentdevEnvironment Name
MinChar3Minimum characters for the random shortened link id
MaxChar3Maximum characters for the random shortened link id
Domainzoph.ioDesired Domain (must be linked to theHostedZoneId Parameter)
SubDomainshortenerDesired subdomain of the API
HostedZoneIdRequiredAWS Route53HostedZoneId where your domain name belongs
FallbackUrlhttps://zoph.ioWhen the url does not exist, fallback url
CertificateArnRequiredArn of the Wildcard ACM Certificate (us-east-1)
AWSRegioneu-west-1AWS Region
AlertsRecipientRequiredEmail of the recipient of CloudWatch Alarms

Deployment

    $ make deploy    $ make setup_front

How to shorten urls?

Using Companion Static Website

Go to the following website after the deployment (depends on your parameters 👆)

Demo:

DemoWebsite

  • https://short.{Domain}

Using theMakefile

    $ make url 'https://google.com'

ℹ️ Simple quotes are important

UsingcURL

curl -X POST https://{subdomain}.{domain}/create/ \--header"Content-Type: application/json" \-d'{"long_url": "https://google.com"}'

Optionnaly, you can change the default TTL value (7 days), by using thettl_in_days attribute in body request:

curl -X POST https://{subdomain}.{domain}/create/ \--header"Content-Type: application/json" \-d'{"long_url": "https://google.com", "ttl_in_days": 365}'

Optionnaly, you can ask for ahuman readable (false by default) short id, ie a suite of consonants/vowels, easier to read/remember.

curl -X POST https://{subdomain}.{domain}/create/ \--header"Content-Type: application/json" \-d'{"long_url": "https://google.com", "ttl_in_days": 3, "human_readable": true}'

Response:

{"short_id":"baho","created_at":"2024-08-24T15:28:04","ttl":1724772484,"short_url":"https://{subdomain}.{domain}/baho","long_url":"https://google.com"}

Note: the generated short id is lowercase to avoid any human mistake.

Response sample
{"created_at":"2023-01-17T13:37:00","long_url":"https://zoph.io","short_id":"dBC","short_url":"https://{subdomain}.{domain}/dBC","ttl":1674561936}

📖 Reference


[8]ページ先頭

©2009-2025 Movatter.jp