GithubHelp home page GithubHelp logo

dvsa / hvt-nearest-atf Goto Github PK

View Code? Open in Web Editor NEW
0.0 9.0 1.0 1.3 MB

AWS Lambda used to deliver the nearest HGV and Bus Mot location with availability

License: MIT License

JavaScript 4.56% TypeScript 50.48% SCSS 2.16% Nunjucks 42.80%

hvt-nearest-atf's Introduction

hvt-nearest-atf

A Serverless Node Express lambda (NearestAtfFunction) for showing nearest ATF centres with their availability.

Requirements

Run Locally

  1. Follow build steps in hvt-data to prepare local dataset
  2. hvt-geolocation and hvt-read-api must be running
  3. npm i
  4. cp .env.development .env
  5. npm run build:dev
  6. npm run start:dev
  7. Go to http://localhost:3007/ on browser

Run and watch Locally

As steps above but instead of build:dev

  • npm run watch:dev

And in a separate terminal, run

  • npm run start:dev

Note: only .ts files are being watched. Any changes to template njk files will not be watched so will not rebuilt.

Debug Locally (VS Code only)

  1. Run lambdas in debug mode: npm run start:dev -- -d 5858
  2. Add a breakpoint to the lambda being tested (src/controllers/index.controller.ts)
  3. Run the debug config from VS Code that corresponds to lambda being tested (NearestAtfFunction)
  4. Go to http://localhost:3007/ on browser

Tests

  • The Jest framework is used to run tests and collect code coverage
  • To run the tests, run the following command within the root directory of the project: npm test
  • Coverage results will be displayed on terminal and stored in the coverage directory
    • The coverage requirements can be set in jest.config.js

Build for Production

  1. npm i
  2. Add environment variables to .env
  3. npm run build:prod
  4. Zip file and minified assets and can be found in ./dist/

Logging

By using a utility wrapper (src/util/logger) surrounding console.log, the awsRequestId and a "correlation ID" is output with every debug/info/warn/error message.

For this pattern to work, every service/lambda must forward their correlation ID to subsequent services via a header e.g. X-Correlation-Id.

In practice, the first lambda invoked by an initial request will not have received the X-Correlation-Id header, so its correlationId gets defaulted to its lambdaRequestId. This correlationId should then be used when invoking subsequent lambdas via the X-Correlation-Id header. Every lambda called subsequently will then check for that X-Correlation-Id header and inject it into their logs.

This shows an example of what the log looks like from the first invoked lambda:

2020-09-10T17:03:04.891Z	5ff37fce-5ace-114c-9120-a1406cc8d11d	INFO	{"apiRequestId":"c6af9ac6-7b61-11e6-9a41-93e8deadbeef","correlationId":"5ff37fce-5ace-114c-9120-a1406cc8d11d","message":"Here's a gnarly info message from lambda 1 - notice how my correlationId has been set to my lambdaRequestId?"}

This shows an example of what the logs look like from the second invoked lambda (called via the first lambda):

2020-09-10T17:05:31.627Z	32ff455b-057d-1dd7-98b8-7034bf182dc8	INFO	{"apiRequestId":"d9222e0a-6bd9-49e0-84dd-ffe0680bd141","correlationId":"5ff37fce-5ace-114c-9120-a1406cc8d11d","message":"Here's a gnarly info message from lambda 2 - notice how my correlationId is the same as the lambda 1"}

hvt-nearest-atf's People

Contributors

alexisc-kainos avatar annadodson avatar bdrozd-kainos avatar faggc avatar ibrahimjassat avatar meridiani avatar sdh100shaun avatar snyk-bot avatar szymonkaczorowski-kainos avatar undermountaink avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

uk-gov-mirror

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.