Giter Site home page Giter Site logo

sudokar / nx-serverless Goto Github PK

View Code? Open in Web Editor NEW
137.0 6.0 15.0 15.66 MB

Modern Serverless framework starter template using Nrwl Nx monorepo dev toolkit

Home Page: https://github.com/sudokar/nx-serverless

License: MIT License

Shell 2.07% JavaScript 2.47% TypeScript 95.46%
serverless template boilerplate scaffolding monoreepo nx starter

nx-serverless's Introduction

nx-serverless-monorepo

serverless esbuild npm peer dependency version (scoped) code style: prettier GitHub license Percentage of issues still open PRs Welcome Maintained

TypeScript GitHub Actions

A monrepo style, modern boilerplate or template project for Serverless framework using Nx monorepo toolkit ๐Ÿ›  and aws-nodejs-typescript serverless template

Table of contents

Whats Included

  • A template project layout using latest version of Nx and Servrless framework
  • An easy to use workspace generator to generate a template/stack with Serverless framework files and related Nx configuration
  • Configured with AWS provider and it can be easily adopted to any cloud provider

Template Layout

.
โ”œโ”€โ”€ stacks/    # stack for each serverless configuration/template and its associated files
โ”œโ”€โ”€ libs/      # shared libraries
โ”œโ”€โ”€ tools/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ jest.config.js
โ”œโ”€โ”€ jest.preset.js
โ”œโ”€โ”€ nx.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ serverless.base.ts  # base configuration for serverless
โ”œโ”€โ”€ tsconfig.base.json
โ”œโ”€โ”€ workspace.json
โ”œโ”€โ”€ .editorconfig
โ”œโ”€โ”€ .eslintrc.json
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .husky              # git hooks
โ”œโ”€โ”€ .nvmrc
โ”œโ”€โ”€ .prettierignore
โ”œโ”€โ”€ .prettierrc

Prerequisites

  • Nodejs protip: use nvm

    โš ๏ธ Version: lts/iron (v20). 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.

  • ๐Ÿ“ฆ Package Manager

  • ๐Ÿ’… Code format plugins

    On your preferred code editor, Install plugins for the above list of tools

Usage

Depending on your prefrered package manager, follow the instructions below to build and deploy serverless stack(s).

  • Install project dependencies

    yarn install
  • Generate a new stack

    nx g serverless <STACK_NAME>

    Run with -d or --dry-run flag for dry run

  • Generate a new library

    nx g @nx/node:lib --skipBabelrc --tags lib <LIBRARY_NAME>

    Run with -d or --dry-run flag for dry run

  • Package stack

    • To package single stack

      nx run <STACK_NAME>:build --stage=<STAGE_NAME>
    • To package stack affected by a change

      nx affected:build --stage=<STAGE_NAME>
    • To package all stacks

      nx run-many --target=build --stage=<STAGE_NAME>
  • Deploy stack to cloud

    • To deploy single stack

      nx run <STACK_NAME>:deploy --stage=<STAGE_NAME>
    • To deploy stack affected by a change

      nx affected:deploy --stage=<STAGE_NAME>
    • To deploy all stacks

      nx run-many --target=deploy --all --stage=<STAGE_NAME>
  • Remove stack from cloud

    • To remove single stack

      nx run <STACK_NAME>:remove --stage=<STAGE_NAME>
    • To remove stack affected by a change

      nx affected:remove --stage=<STAGE_NAME>
    • To remove all stacks

      nx run-many --target=remove --all --stage=<STAGE_NAME>
  • Run tests

    • To run tests in single stack

      nx run <STACK_NAME>:test --stage=<STAGE_NAME>
    • To run tests affected by a change

      nx affected:test --stage=<STAGE_NAME>
    • To run tests in all stacks

      nx run-many --target=test --all --stage=<STAGE_NAME>
  • Run offline / locally

    • To run offlline, configure serverless-offline plugin as documented here and run below command

      nx run <STACK_NAME>:serve --stage=<STAGE_NAME>
  • Understand your workspace

    nx dep-graph
    

Further help

Nx Cloud

Computation Memoization in the Cloud

โ€‹ Nx Cloud pairs with Nx in order to enable you to build and test code more rapidly, by up to 10 times.

โ€‹ Visit Nx Cloud to learn more and enable it

Contribution

Found an issue? feel free to raise an issue with information to reproduce.

Pull requests are welcome to improve.

Support

Like the template?

Click to Buy Me A Coffee

Or, Add a star โญ to the repository

Maintainer

This template is authored and maintained by sudokar

License

MIT

nx-serverless's People

Contributors

dependabot[bot] avatar netanelbasal avatar renovate-bot avatar renovate[bot] avatar sudokar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nx-serverless's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v4
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
.github/workflows/main.yml
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • @swc/helpers 0.5.6
  • tslib 2.6.2
  • @aws-sdk/types 3.535.0
  • @jest/transform 29.7.0
  • @nrwl/tao 18.2.4
  • @nx/devkit 18.2.4
  • @nx/eslint 18.2.4
  • @nx/eslint-plugin 18.2.4
  • @nx/jest 18.2.4
  • @nx/js 18.2.4
  • @nx/node 18.2.4
  • @nx/plugin 18.2.4
  • @nx/workspace 18.2.4
  • @swc-node/register 1.9.0
  • @swc/cli 0.3.9
  • @swc/core 1.4.8
  • @swc/jest 0.2.36
  • @types/aws-lambda 8.10.137
  • @types/jest 29.5.12
  • @types/node 20.12.7
  • @types/serverless 3.12.22
  • @typescript-eslint/eslint-plugin 7.7.0
  • @typescript-eslint/parser 7.7.0
  • esbuild 0.20.0
  • eslint 8.57.0
  • eslint-config-prettier 9.1.0
  • husky 9.0.11
  • jest 29.7.0
  • jest-environment-node 29.7.0
  • lint-staged 15.2.2
  • nx-cloud 18.0.0
  • prettier 3.2.5
  • serverless 3.38.0
  • serverless-esbuild 1.52.1
  • serverless-jest-plugin 0.4.0
  • serverless-offline 13.3.4
  • ts-jest 29.1.2
  • ts-loader 9.5.1
  • ts-node 10.9.2
  • typescript 5.4.5
  • node 20
  • yarn 4.1.1
tools/workspace-plugin/package.json
nvm
.nvmrc

  • Check this box to trigger a request for Renovate to run again on this repository

NX style configuration swap

NX supports swapping files depending on configuration (i.e. production vs local dev). Any idea how to accomplish this with your pattern?

Problems not using yarn

When we try to add new workspace to the project, and don't have yarn installed (we don't use it with my team), we have this error :

/bin/sh: yarn: command not found
node:internal/errors:841
  const err = new Error(message);
              ^

Error: Command failed: yarn --version
/bin/sh: yarn: command not found

    at checkExecSyncError (node:child_process:828:11)
    at execSync (node:child_process:899:15)
    at getPackageManagerVersion (/Users/User/test/nx-serverless-main/node_modules/nx/src/utils/package-manager.js:98:41)
    at Object.yarn (/Users/User/test/nx-serverless-main/node_modules/nx/src/utils/package-manager.js:40:33)
    at getPackageManagerCommand (/Users/User/test/nx-serverless-main/node_modules/nx/src/utils/package-manager.js:89:36)
    at compileToolsDir (/Users/User/test/nx-serverless-main/node_modules/nx/src/command-line/workspace-generators.js:72:64)
    at compileTools (/Users/User/test/nx-serverless-main/node_modules/nx/src/command-line/workspace-generators.js:53:5)
    at Object.<anonymous> (/Users/User/test/nx-serverless-main/node_modules/nx/src/command-line/workspace-generators.js:26:24)
    at Generator.next (<anonymous>) {
  status: 127,
  signal: null,
  output: [
    null,
    Buffer(0) [Uint8Array] [],
    Buffer(33) [Uint8Array] [
       47,  98, 105, 110,  47, 115, 104,  58,
       32, 121,  97, 114, 110,  58,  32,  99,
      111, 109, 109,  97, 110, 100,  32, 110,
      111, 116,  32, 102, 111, 117, 110, 100,
       10
    ]
  ],
  pid: 66866,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(33) [Uint8Array] [
     47,  98, 105, 110,  47, 115, 104,  58,
     32, 121,  97, 114, 110,  58,  32,  99,
    111, 109, 109,  97, 110, 100,  32, 110,
    111, 116,  32, 102, 111, 117, 110, 100,
     10
  ]
}

Documentation out of date

Command no longer works: nx workspace-generator serverless <STACK_NAME>

Error:

 NX   Workspace Generators are no longer supported                       
                                                                            
   Instead, Nx now supports executing generators or executors from          
   local plugins. To run a generator from a local plugin,                   
   use `nx generate` like you would with any other generator.               
                                                                            
   For more information, see: https://nx.dev/deprecated/workspace-generators


 >  NX   Unable to resolve @nx-serverless-template/workspace-plugin:serverless,test.

   Cannot find module '@nx-serverless-template/workspace-plugin/package.json'
   Require stack:
   - C:\dev\sbg-web\nx-serverless\node_modules\nx\src\utils\package-json.js
   - C:\dev\sbg-web\nx-serverless\node_modules\nx\src\utils\package-manager.js
   - C:\dev\sbg-web\nx-serverless\node_modules\nx\bin\init-local.js
   - C:\dev\sbg-web\nx-serverless\node_modules\nx\bin\nx.js
   Pass --verbose to see the stacktrace.

Think this might be due NX deprecating generators in favor of Plugin's

serverless offline for all lambdas

Hello, quick question, is there any way to run serverless offline start and execute ALL stacks at the same time? or do you need to manually run one by one?

I'm looking a way to use something like your repo but with the avility to run all functions at the same time (as I do currently with the manual setup

Thanks!

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.