Git Product home page Git Product logo

hasura-aws-stack's Introduction

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 [email protected]: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.

hasura-aws-stack's People

Contributors

arvi3411301 avatar coco98 avatar praveenweb avatar tirumaraiselvan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hasura-aws-stack's Issues

AWS cli throws error if GITSHA is only numbers

An error occurred (ValidationException) when calling the GetAlias operation: 1 validation error detected: Value '7651210' at 'name' failed to satisfy constraint: Member must satisfy regular expression pattern: (?!^[0-9]+$)([a-zA-Z0-9-_]+)

CFT Template

Would be nice if you had a cft template we could use.

Readme not enough

Hello,

The 5 steps explaining how to deploy to AWS are useless. It's not detailed enough. Hard work was done to do this stack and not even a paragraph explaining how to deploy it properly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.