instedd / shorter

Serverless URL shortener
1 stars 1 forks source link
aws aws-sam sam serverless url-shortener

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:

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:

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
...