- An AWS Account
- A domain name that will function as your "short url" domain. Preferably this domain is one purchased in Route53.
- Note: You will need to have the domain purchased before executing any steps to set the url shortener up.
- You will need the following software installed on your machine/in your local environment:
- Ensure your AWS credentials (with sufficient permissions) are configured locally--recommended
in
$HOME/.aws/credentials
--so that terraform will be able to successfully create IAM, API Gateway, DynamoDB, and Lambda resources.
- Clone this repo and then
cd
inside the project root:
git clone git@github.com:jdelnano/serverless-golang-url-shortener.git
cd serverless-golang-url-shortener
- From the project root directory, create all AWS resources/infrastructure via
terraform
:
# I recommend running a `terraform plan` first, inspecting it to make sure
# terraform won't do anything unexpected in your AWS environment
terraform plan
# if all looks good, then apply!
terraform apply
- That should be it! If for some reason your API seems to not be active, you may need to go into API Gateway and perform a 'deploy' of you API:
If you find that you want to make updates to either ./lambdas/shorten/main.go
and/or ./lambdas/redirect/main.go
you'll need to then execute (ideally from the repository directory):
./deploy_updated_lambda.sh
The helper script will build all new binaries, compress them, and if you press ENTER, will perform a terraform apply
.
To create a shortened url, execute the command below from any machine:
curl -X POST \
'https://joedelnano.com/shorten' \
--header 'Content-Type: application/json' \
--data-raw '{"url": "https://example.com/long-url-that-you-wish-to-shorten"}'
Example response:
https://joedelnano.com/af43i
In a browser, copy and paste your shortened URL (e.g. https://joedelnano.com/af43i
) and see the magic work!