Serverless URL shortener powered by AWS services
brew install go
)brew install awscli
or check https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)brew tap aws/tap; brew install aws-sam-cli
or check https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)Using the AWS CLI create a new bucket where the deployment packages will be uploaded:
$ aws s3 mb s3://my-deploy-bucket
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:
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
Steps to expose the API with a hostname are out of the scope of this document, but in short you need:
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
...