Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

themse/pp-faas-aws

Repository files navigation

Imaginary Sales Department (ISD) - Backend

A service that provides you with an easy way to manage potential Leads and their respective Interests.

Running this project locally

  • Install all dependencies:
 npm i
  • Install serverless tool globally or use npx
 npm i -g serverless

or

 npx serverless
  • Install DynamoDB
npx sls dynamodb install

Start working with API

  • Start application in offline mode:
npm run start:dev
  • Also we can invoke a single function:
npm run invoke:local -- -f <functionName>
  • We can run function in debug mode to see additional logs
npm run invoke:local:debug -- -f <functionName>

Check the sls invoke local command documentation for more information.

Remotely

We can use Postman or Insomnia to test api (in future it will be swagger).

Basic requests

  • Create a lead
curl --location --request POST 'http://localhost:4500/lead' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email":"[email protected]",
    "phone":"(012) 2345 6789",
    "firstName":"Jack",
    "lastName":"Russel"
}'
  • Add lead interest (we can get leadId from the previous request)
curl --location --request POST 'http://localhost:4500/interest' \
--header 'Content-Type: application/json' \
--data-raw '{
    "leadId": "eab29a17-4f5d-4285-9c71-ed78a7d833b1",
    "message": "hello world"
}'
  • Find all leads with their interests
curl --location --request GET 'http://localhost:4500/leads' \
--header 'Content-Type: application/json' 

Template features

Project structure

The project code base is mainly located within the src folder. This folder is divided in:

  • common - containing common features for the entire project
  • functions - containing code base and configuration for your lambda functions
  • middlewares - containing middleware list for each lambda function
  • models - containing your business models
  • services - containing abstractions for external services
  • utils - containing tools and helpers

Serverless Framework is configured in:

  • serverless.ts - main configuration file
  • serverless - a folder with partials configurations

Tech stack

Here's a brief high-level overview of the tech stack the ISD App uses:

  • Node.js v.14.17.6 - a JavaScript runtime built on Chrome's V8 JavaScript engine.
  • Serverless v.2.70.0 - framework for the creation and management of the Serverless infrastructure
  • AWS Cloud Provider - cloud provider with more than 100 products.
  • AWS DynamoDB - Amazon DynamoDB is a fully managed, serverless, key-value NoSQL database designed to run high-performance applications at any scale.
  • Typescript - is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.

Deployment

Firstly check if you authorized in aws console.

  • Build the project before deployment (in folder .serverless)
npm run build
  • Deploy the whole application to the cloud:
npx run deploy:all
  • Deploy a single function
npx run deploy:function -- -f <functionName>
  • For more details
npx run deploy:function -- --help

Testing

Application services are covered by unit tests with jest. Run tests with npm scripts:

npm run test

or

npm t

Future steps

  • Swagger
  • Authorization