This app creates a URL shortener without using any compute. All business logic is handled at the Amazon API Gateway level. The basic app will create an API Gateway instance utilizing Cognito for authentication and authorization. It will also create an Amazon DynamoDB table for data storage. It will also create a simple Vuejs application as a demo client.
Read the blog series about this application:
- Building a serverless URL shortener app without AWS Lambda – part 1
- Building a serverless URL shortener app without AWS Lambda – part 2
- Building a serverless URL shortener app without AWS Lambda – part 3
There is no Amplify, Cognito, Cloud Front. You will target the API directly.
Authentication is done using API Gateway API Keys. You must configure one and provide a key in your queries header using the X-API-Key
header.
DynamoDB table now allows item auto expiration after one month. We add a new field expiration
to all entries and set the table to use this field
to auto expire items.
owner
is now set to bFAN
and not dynamic as there is no more Cognito UserPool but you can change it directly in the api.xml
file.
-
Forked copy of this repository. Instructions for forking a GitHib repository can be found here
-
A GitHub personal access token with the repo scope as shown below. Instructions for creating a personal access token can be found here
Be sure and store you new token in a place that you can find it.
In the terminal, use the SAM CLI guided deployment the first time you deploy
sam deploy -g
You can choose the default for all options except GithubRepository and **
## The name of the CloudFormation stack
Stack Name [URLShortener]:
## The region you want to deploy in
AWS Region [eu-west-1]:
## The name of the application (lowercase no spaces). This must be globally unique
Parameter AppName [shortener]:
## Shows you resources changes to be deployed and requires a 'Y' to initiate deploy
Confirm changes before deploy [y/N]:
## SAM needs permission to be able to create roles to connect to the resources in your template
Allow SAM CLI IAM role creation [Y/n]:
## Save your choice for later deployments
Save arguments to samconfig.toml [Y/n]:
SAM will then deploy the AWS CloudFormation stack to your AWS account and provide required outputs for the included client.
After the first deploy you may re-deploy using sam deploy
or redeploy with different options using sam deploy -g
.
You must include the X-API-Key
Header in your http queries to authenticate with API Gateway. The Key is available in API Gateway API Keys
section in the console.
The URLs to call are:
- POST
shorter.bfansports.com/app
: Create a new short URL.- body:
{"id":"ABCDEFGHIJ12345", "url":"https://the.url.I.want.to.reach.com"}
- body:
- GET
shorter.bfansports.com/${id}
: Get the URL associated with an ID- path: The ID of the URL to redirect to
Other calls are available. See the api.yaml
file