Skip to content

onema/ServerlessLink

Repository files navigation

Serverless Link

Build Status LICENSE

Serverless link is a Serverless URL Shortener build on µServerless and Scala and deployed using the serverless framework.

Demo

Checkout the ServerlessLink website for a demo!

Requirements

  1. java JDK 8+ (download)
  2. sbt 1+ (install)
  3. Serverless Framework 1.30+ (install)

Optional

  1. python 3.6+ (download)
  • This is used to install the AWS CLI and move the website assets into the S3 bucket

Using docker

Alternatively you can use the onema/userverless-build docker container to build and deploy your application:

docker run -it --rm -v $HOME/.aws/:/root/.aws/ -v $PWD:/root/app onema/userverless-build bash

Setup

DNS Setup

You need a Route 53 hosted zone for the domain that you will be using in this project. This project assumes that you will be using a second-level domain name e.g. test.com as this name is used to look up the Route 53 hosted zone. If you want to use a sub-domain e.g. link.test.com, you will need to modify the resources WebsiteDomainRecordSet and ApiDomainRecordSet in the link-resources_cfn.yml file to use the proper HostedZoneName or HostedZoneId. See [AWS::Route53::RecordSet][1] and [Alias Resource Record Set for a CloudFront Distribution][2] for more information [1]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset.html [2]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-route53.html#w2ab1c17c23c81c11

Create the assembly

sbt assembly

Deploy the code using serverless

serverless deploy --domain <DOMAIN_NAME>

The <DOMAIN_NAME> is the domain you will be using for your application. This will create a bucket with the given domain name and create two DNS Record Sets in Route 53, one for the website and another one for the API.

Serverless will use the file infrastructure/link-resources_cfn.yml and generate the following resources:

  • Website Bucket (to place the application files)
  • DynamoDB table (where the link mappings are saved)
  • ACM certificate for the Website
  • ACM certificate for the API
  • Domain Mapping for the API (the domain will be m.<DOMAIN_NAME>)
  • CloudFront distribution for the website
  • Record set entry in Route 53 for the website
  • Record set entry in Route 53 for the API

IMPORTANT:

The process will not finished until the ACM Certificates have been approved, the approval process requires a DNS entry, you can see the instructions to add the DNS record in the ACM control panel.

To push the website code to the bucket use the following command

aws s3 cp ./public/ s3://<DOMAIN_NAME> --recursive

Application configuration

The application needs a config.js file. You can copy the public/js/config.js.dist to public/js/config.js. All you need to fill in is the name of the invokeUrl which is the URL of your API m.<DOMAIN_NAME>, and the scheme, this should be https.

Optional setup Build/Deploy service for your application

I have included a cloud formation template infrastructure/code-build-cicd_cfn.yml to generate a CodeBuild service. This service can be used to deployed your serverless application any time you push code to a branch in your GitHub repository (the branch is defined in the template parameters).