DocsGuidesGitHub

Quick start

This document outlines the steps to get a Saruni application deployed as succinctly as possible. Check other documents for the specifics on steps.

Pre-requisites

Ensure you have the following installed:

After creating Saruni project

  • Add accessToken to .env
  • Add refreshToken to .env
  • Add DATABASE_URL to .env

Deploy to development environment

  • Create root AWS account
  • Create AWS organization
  • Create dev account
  • Create CLI access on dev account
  • Copy access_key_id and secret_key_id to ~/.aws/credentials under a new profile
  • Add the name of the profile to saruni.json under serverless.dev.awsProfile
  • Create bastion key with command yarn sr create-key
  • Add project name to saruni.json
  • Create env variables in AWS System Manager in a format like: /${yourProjectName}/DBName/dev
  • Deploy resources with yarn deploy --service=resources
  • Copy the CloudFront domain to saruni.json under serverless.dev.frontendUrl and serverless.dev.cloudfrontUrl and prefix the domain with https://
  • Deploy the GraphQL service with yarn sr deploy --resource=graphql
  • Copy the the endpoint of the API without /graphql, like https://{id}.execute-api.eu-west-1.amazonaws.com/dev, to saruni.json, and in there serverless.dev.domainUrl
  • Copy the name of your frontend bucket from S3 to saruni.json, serverless.dev.frontendS3Bucket, it should be something like resources-dev-frontendbucket-{id}
  • Copy the your CloudFront distribution ID (like E6ACKOF13NAJ7) to saruni.json serverless.dev.distId
  • Deploy the web service with yarn sr deploy --stage=web
  • Deploy the auth service with yarn sr deploy --stage=auth
  • Create an SSH tunnel with the command ssh -L 2222:${yourDBPort}:5432 -i dev-bastion-key.pem ec2-user@${yourEC2domain}
  • In another tab apply a migration with yarn sr db migrate up --stage=dev

Deploy to production environment

  • Create a prod account
  • Create CLI access on prod account
  • Copy access_key_id and secret_key_id to ~/.aws/credentials under a new profile
  • Add the name of the profile to saruni.json under serverless.prod.awsProfile
  • Create bastion key with command yarn sr create-key --stage=prod
  • Buy your domain (the easiest way being through AWS Route53)
  • Add the domain you would like your API in saruni.json serverless.prod.domainName, like chat-api.saruni-samples.com
  • Add the web domain you would like your web to serverless.prod.frontendDomain in saruni.json, like chat.saruni-samples.com
  • Add the web URL you would like your web to serverless.prod.frontendUrl in saruni.json, like https://chat.saruni-samples.com
  • Create SSL certificate for your domain, with name of your domain and alternate name prefixed with wildcard, like saruni-samples.com and *.saruni-samples.com
  • Add the ARN of your SSL certificate to serverless.prod.certificateArn
  • Add the hosted zone id of your chosen domain to serverless.prod.hostedZoneId
  • Create env vars in AWS System Manager in a format like: /${yourProjectName}/DBName/prod
  • Deploy resources with yarn deploy --service=resources --stage=prod
  • Copy the CloudFront domain to saruni.json under serverless.prod.cloudfrontUrl and prefix the domain with https://
  • Copy the name of your frontend bucket from S3 to saruni.json under serverless.dev.frontendS3Bucket, it should be something like resources-dev-frontendbucket-1stc7i12ez8nh
  • Copy the your CloudFront distribution id (like E6ACKOF13NAJ7) to saruni.json serverless.dev.distId
  • Create custom domain for your API with yarn sr deploy --service=domain
  • Deploy the GraphQL service with yarn sr deploy --resource=graphql
  • Deploy the web service with yarn sr deploy --stage=web
  • Deploy the auth service with yarn sr deploy --stage=auth
  • Create an SSH tunnel with the command ssh -L 2222:${yourDBPort}:5432 -i dev-bastion-key.pem ec2-user@${yourEC2domain}
  • In another tab do the migration with yarn sr db migrate up --stage=prod