Skip to content

Installation

Hlambda is the implementation of the idea to load your ECMAScript code as configuration (metadata). With Hlambda you can easily create microservice that can load arbitary code configuration.

Image title

Main usecase was to implement microservice that will run Hasura custom actions in a separate container. Hlambda is supposed to be used in combination with Hasura and Postgres but it can be used as stand alone API server.

docker run -d -p 8081:1331 --env HLAMBDA_ADMIN_SECRET=demo --name hlambda-server --restart=always -v hlambda_metadata:/usr/src/app/metadata hlambda/hlambda-core:latest
curl https://www.hlambda.io/raw/code/start/docker-compose.yaml -o docker-compose.yaml

Here is docker-compose.yaml file that will run the Hasura/Hlambda stack:

version: '3.6'
services:
  postgres:
    image: postgres:12
    restart: always
    volumes:
    - hasura_db_data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: postgrespassword
  graphql-engine:
    image: hasura/graphql-engine:v2.3.0-beta.1
    ports:
    - "8080:8080"
    depends_on:
    - "postgres"
    restart: always
    environment:
      HASURA_GRAPHQL_METADATA_DATABASE_URL: "postgres://postgres:postgrespassword@postgres:5432/postgres"
      HASURA_GRAPHQL_ADMIN_SECRET: "demo"
      HASURA_GRAPHQL_ENABLE_TELEMETRY: "false"
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
      HASURA_GRAPHQL_DEV_MODE: "true"
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: "startup, http-log, webhook-log, websocket-log, query-log"
      HASURA_GRAPHQL_JWT_SECRET: '{"claims_namespace_path":"$$", "type":"RS256", "key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxITajyliCtRFJ9SLPbGs\n8+uL/FZok7big7zQ6lQUJ/3s+MndrLoAhbBZuaf1RKhzWRkizV7I3BetbZ86Iyir\nt0Fp7Lu0Rtyq5GH1O9vAYh5wdp1bQ1t45v/ifR4/Y7C97qq1e1IoelpJxlkEUAN2\nELBMYJ1SGIl94BKgDoF835H68X/s+bKJHoFYPyGPeJbdNFAmYGgrZMleid+bT3Qr\neijMoMuIj1XVMSlN405QWeNqFMGVB73gjhsc3pmyePUBbi67Va+pEBsbexYVsvqO\nynQYlSExbJfHcNL+f0sYrXsGmsPnFji2JWsE3LEUb6Xgab+zmZb+0NcXzMu+t7Hr\ndwIDAQAB\n-----END PUBLIC KEY-----\n"}'
      ACTION_BASE_URL: "http://hlambda-core:1331"
  hlambda-core:
    image: hlambda/hlambda-core:latest
    environment:
      HLAMBDA_ADMIN_SECRET: 'demo'
      HASURA_GRAPHQL_API_URL: "http://graphql-engine:8080"
      HASURA_GRAPHQL_ADMIN_SECRET: "demo"
    ports:
      - "8081:1331"
    restart: always
    volumes:
      - hlambda_metadata:/usr/src/app/metadata

volumes:
  hasura_db_data:
  hlambda_metadata:
  • Note: Hlambda can also be used without docker, just clone the hlambda-core repository and run it directly with npm start.

Install Hlambda CLI

$ npm install -g hlambda-cli

How to use Hlambda CLI

$ hlambda --version
$ hlambda init my-first-hlambda-app
$ cd my-first-hlambda-app

Change the admin_secret in the config.yaml manually or just run:

$ hlambda config save --admin-secret "demo"

this will edit the config.yaml file and save admin secret value in that file (please take extra care when commiting config.yaml file to not leak secrets)

(Optionaly) You can check the structure of the initial demo codebase or edit any part of the code with "Visual Studio Code" before deploying(applying metadata) by running:

$ code .

You can now apply the changes by running:

$ hlambda metadata apply

Done! You can use curl to test the API or even better hlambda cli for the simple test:

$ hlambda request get demo
$ curl -s -X GET http://localhost:8081/demo

you can also get the remote logs by running:

$ hlambda server logs

or with aliases

$ hlambda s l

If you want to check your new API in browser just run:

$ hlambda console

Happy hacking!

Back to top