1.2.0 • Published 2 years ago

atlas-metrics-service v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Atlas Metrics - Serverless Project Template

This project has been generated using the v1 template from Atlas Metrics.

Installation/deployment instructions

Depending on your preferred package manager, follow the instructions below to deploy your project.

Requirements: NodeJS lts/fermium (v.14.15.0). If you're using nvm, run nvm use to ensure you're using the same Node version in local and in your lambda's runtime.

Using NPM

  • Run npm i to install the project dependencies
  • Run npx sls deploy --stage ENVIRONMENT to deploy this stack to AWS. Default environment value is dev

Using Yarn

  • Run yarn to install the project dependencies
  • Run yarn sls deploy --stage ENVIRONMENT to deploy this stack to AWS. Default environment value is dev

Test your service

This project uses Cucumber to run integration tests. Please note that you should have a running instance of serverless offline running.

# Preparation
## Open a terminal tab and run
cd /path/to/db-service-repository && yarn dev
## Open another tab and run
cd /path/to/this-repository && yarn dev

# Execution
## Open a third tab and run all feature files
yarn test:api
## Open a third tab and run a single feature file
yarn test:api CreateOrganization
## Open a third tab and run mulitple feature files
yarn test:api CreateOrganization SelectEsgStandards

Locally

In order to test the Hello function locally, run the following command:

  • npx sls invoke local -f Hello --path src/handler-mock.json if you're using NPM
  • yarn sls invoke local -f Hello --path src/handler-mock.json if you're using Yarn

Check the sls invoke local command documentation for more information.

If you need to simulate API Gateway locally, please install the serverless-offline plugin.

Remotely

Copy and replace your url - found in Serverless deploy command output - and name parameter in the following curl command in your terminal or in Postman to test your newly deployed application.

curl --location --request POST 'https://myApiEndpoint/dev/hello' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "John Doe"
}'

Project features

Project structure

The project code base is mainly located within the src folder.

.
├── src
├── package.json
├── serverless.yml              # Serverless service file
├── tsconfig.json               # Typescript compiler configuration
└── webpack.config.js           # Webpack configuration

Linter and pre-commit hook

This project is configured with TypeScript ESLint and Husky to validate the code syntax before any commit.

Error tracking

This project is pre-configured with Sentry using the serverless-sentry plugin. An example of how to enable error tracking can be found in the Hello sample function.

The configuration contains global properties for Atlas Metrics such as organization and authToken, however a new project needs to be created and further configuration of the project is necessary.

Run the following command to create a new project. Please make sure to replace the name and slug with the correct values.

`~bash curl https://sentry.io/api/0/teams/atlas-metrics/atlas-metrics/projects/ \ -H 'Authorization: Bearer 27ac46de035e4e0781f94f911cab5131b0365d2bffd249c390582a374788dbd6' \ -H 'Content-Type: application/json' \ -d '{"name":"Atlas Metrics Demo Service","slug":"atlas-metrics-demo-service", "platform": "node-awslambda"}'

Once created, please copy the DNS URL from _Settings -> Projects -> Client Keys (DSN)_ in [sentry.io](https://sentry.io/) and add it to the `dns` field in the Sentry configuration of the `serverless.yml` file. Also replase the `project` property by the slug value used.