Skip to content
A complete production ready 100% serverless stack on AWS with Hasura
JavaScript Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci refactor nextjs package.json Apr 9, 2019
custom/nextjs-serverless refactor nextjs package.json Apr 9, 2019
event-triggers update ecs to add env variable Feb 13, 2019
hasura
local Update localDevelopment.js Feb 13, 2019
remote-schemas remove file Mar 11, 2019
.gitignore
README.md Update README.md Oct 29, 2019

README.md

hasura-aws-stack

Stack

  • Hasura on ECS Fargate (auto-scale)
  • Aurora Postgres or RDS Postgres
  • Lambdas for remote schemas and event triggers
  • Docker for local dev
  • CircleCI for CI/CD

Setup Hasura on Fargate

  1. Go to ECS in AWS Console.
  2. Create a ECS cluster on Fargate with required specs.
  3. Create a service called hasura in your cluster.
  4. Create a Task Definition with Hasura GraphQL Engine container and environment variables.
  5. Add the Task to your hasura service.

If you are want to use multiple-instances/auto-scale, you will need to choose an ALB as the load balancer.

Local Dev

  1. Git clone this repo:
$ git clone git@github.com:hasura/hasura-aws-stack.git
$ cd hasura-aws-stack
$ # You are now in the project directory
  1. Run Hasura using docker-compose ref :
In project directory:

$ cd local
$ docker-compose up -d
  1. Start local development API server ( first make sure all dependencies are met for local API server):
In project directory:

$ # install dependencies for local API server for e.g. all remote schemas and event triggers
$ # cd remote-schemas/account-schema
$ # npm i

$ cd local
$ node localDevelopment.js
  1. Apply migrations locally
In project directory;

$ cd hasura
$ hasura migrate apply
  1. Start the console
In project directory:

$ cd hasura
$ hasura console

Local Dev - Event Triggers

  1. Create a new folder in event-triggers folder:
In project directory:

$ cd event-triggers
$ mkdir echo
  1. Write your function in echo/index.js. Make sure you export one function. Ref: echo

  2. Add corresponding endpoint in local development API server. Ref: localDevelopment

  3. Start the local development API server:

In project directory:

$ cd local
$ node localDevelopment.js
  1. Add event trigger URL as environment variable in local/event-triggers.env. Ref: event-triggers.env

  2. Restart Hasura (for refreshing environment variables):

In project directory:

$ cd local
$ docker-compose down
$ docker-compose up -d
  1. Add event trigger through Hasura console using the above environment variable as WEBHOOK_URL.

Local Dev - Remote Schemas

  1. Create a new folder in remote-schemas folder:
In project directory:

$ cd remote-schemas
$ mkdir hello-schema
  1. Write your graphql functions in hello-schema/index.js. Make sure you export the typedefs and resolvers. Ref: hello

  2. Add corresponding server setup in local development API server. Ref: localDevelopment

  3. Start the local development API server:

In project directory:

$ cd local
$ node localDevelopment.js
  1. Add remote schema URL as environment variable in local/remote-schemas.env. Ref: remote-schemas.env

  2. Restart Hasura (for refreshing environment variables):

In project directory:

$ cd local
$ docker-compose down
$ docker-compose up -d
  1. Add remote schema through Hasura console using the above environment variable as GraphQL Server URL.

CI/CD with CircleCI

We want to keep 3 environments in the cloud:

  1. Dev
  2. Staging
  3. Prod

The CI/CD system will deploy the application to each environment based on the branch on which the code is pushed:

branch environment
master dev
staging staging
prod prod
  1. Start by creating a project in CircleCI.

  2. Add your git repo in your CircleCI dashboard. This repo has all the CircleCI configuration in .circleci/config.yml file.

  3. Create an API Gateway per environment (copy the REST_API_ID).

  4. Create a Lambda Basic Execution Role (name it lambda-basic-role): ref

  5. Configure environment variables in your CircleCI project from the dashboard. This example requires the following environment variables:

    AWS_ACCOUNT_ID

    AWS_REGION

    AWS_ACCESS_KEY_ID

    AWS_SECRET_ACCESS_KEY

    AWS_DEV_REST_API_ID

    AWS_DEV_HASURA_ECS_CLUSTER

    AWS_DEV_TASK_FAMILY

    HASURA_DEV_ENDPOINT

    HASURA_DEV_ACCESS_KEY

    AWS_STG_REST_API_ID

    AWS_STG_HASURA_ECS_CLUSTER

    AWS_STG_TASK_FAMILY

    HASURA_STG_ENDPOINT

    HASURA_STG_ACCESS_KEY

    AWS_PROD_REST_API_ID

    AWS_PROD_HASURA_ECS_CLUSTER

    AWS_PROD_TASK_FAMILY

    HASURA_PROD_ENDPOINT

    HASURA_PROD_ACCESS_KEY

  6. Git push or merge PR to master branch. This will deploy to dev environment.

  7. Once you have tested the dev environment, you can promote to staging and prod environments by merging dev with staging and staging with prod respectively.

You can’t perform that action at this time.