Skip to content

instedd/shorter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shorter

Serverless URL shortener powered by AWS services

Install

Requirements

Create a S3 bucket

Using the AWS CLI create a new bucket where the deployment packages will be uploaded:

$ aws s3 mb s3://my-deploy-bucket

Build and deploy

The deployment can be executed in a single step running:

$ make install S3_BUCKET=my-deploy-bucket STACK_NAME=my-stack-name

That command will:

  • Compile lambda handlers written in Go
  • Build a AWS SAM deployment package (CloudFormation package) and upload to the S3 bucket
  • Deploy or upgrade the CloudFormation stack and wait until it's completed

Create API keys

In order to use the service at least one [API Key] and Usage Plan must be created to access the API. This can be done from the AWS Console. For details check: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html

Expose the API with a nice and short hostname

Steps to expose the API with a hostname are out of the scope of this document, but in short you need:

  • Registered domain name
  • The zone for the domain name registered in Route53
  • Certificate for the domain generated by the AWS Certificate Manager
  • A custom domain declared within Amazon API Gateway pointing to the "Prod" stage of the API
  • An entry within the domain zone aliasing the target domain name

Usage

To create new short URL entries in the service use the POST /api/v1/links endpoint passing the desired target url in the query string. For example:

$ curl -XPOST https://nnn.dd/api/v1/links?url=https://google.com -H "X-Api-Key: Mq1lLPeXe99bfjUc4hWnn7R0iqY2CeWNza292yw0"

{"key":"YdhnqV","url":"https://google.com"}

Once the entry is created the short url can be used

$ curl -v https://nnn.dd/YdhnqV

...
HTTP/1.1 302
Location: https://google.com
...