Giter VIP home page Giter VIP logo

beoi-api's Introduction

beOI API

This project is a lambda-powered micro-service library in support for various beOI service.

Overview

This project uses Serverless project to deploy easily serverless functions on AWS Lambda. The developer should refer to Serverless doc for more info.

Requirements

The following list of tools is required. It may work with lower version, but with no guarantees.

  • nodejs >= 6.10
  • npm >= 4.1

Quick-start

Install the packages

To install locally the packages required for development and running the project, run npm install.

Test the first service

You should already be able to call your first REST service locally:

./node_modules/serverless/bin/serverless invoke local -f index

You can follow the path from the service definition to the implementation through serverless.yml, handle.js and lib/status.js.

Install a local database

To be able to test the services locally, you need to install a Postgres database. The easiest way to have exactly the same version as the production server and to avoid the installation hassle is to run it in a container. Install Docker, then run it with:

docker run --name beoiapidb -p 5432:5432 --rm -e POSTGRES_PASSWORD=secret postgres:9.6.1

Then, configure your config/db.json file with your database settings. You can start by copying config/db.sample.json file and adapt it. Note the root keys are the environment, to run it locally only, keep "dev".

To manage your database (e.g., add content), use an external tool such as PGAdmin (UI) or directly the psql client (using another docker container for instance) (CLI).

Setup the database

To make your database is correctly installed and to install the latest version of the database schema, run

./node_modules/db-migrate/bin/db-migrate up --config config/db.json -e dev

Each time you pull a database migration from the repository, do not forget to rerun this command.

Test a first service against the database

You should now be able to call a service locally to your local database:

./node_modules/serverless/bin/serverless invoke local -f ping

You can follow the path from the service definition to the implementation through serverless.yml, handle.js and lib/status.js.

Deployment into Production

In production, the code run on AWS, so you first need to configure your environment for it.

Configure your AWS credentials

If you do not have AWS credentials configured yet for your unix user, configure it using classical AWS tools or Serverless's. You can modify your own ~/.aws/credentials if you need to update them later.

Run a migration

If you need to run migration, you need direct access to the database, so to configure config/db.json for the "prod" key. To test whether a migration needs to be executed and run it if needed, use:

./node_modules/db-migrate/bin/db-migrate up --config config/db.json -e prod

Deployment

To redeploy the full stack:

./node_modules/serverless/bin/serverless deploy

To (re)deploy a single function:

./node_modules/serverless/bin/serverless deploy function -f ping

To run this function in the cloud:

./node_modules/serverless/bin/serverless deploy function -f ping

beoi-api's People

Contributors

smadbe avatar technici4n avatar

Watchers

 avatar  avatar  avatar

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.