Code Monkey home page Code Monkey logo

serverless-template-aws-webpack-nodejs's Introduction

Note

This project has been archived in favor of serverless-template-aws-webpack-typescript

Functions split

Boilerplate template for Serverless allowing to easily separate each function into it's own dedicated file or folder.

The template is for NodeJS 18.x and it uses webpack plugin to reduce each packaged function.

Project creation

sls create --template-url https://github.com/DanielMuller/serverless-template-aws-webpack-nodejs/tree/master/ --path my-new-service --name awesome-service

Configuration

Create and edit config/dev.yml and config/production.yml to suit your needs.

Run nvm use to load the right node version and npm install to install all the dependencies.

File structure

  • events/ Store all events related to testing
  • lib/config.js Javascript module to build serverless.yml
  • resources/ Contains yml files describing each resource. Definitions can be nested 2 levels deep, in a subfolder describing the AWS resource, like IamRole/specificServiceRole.yml. The folder name is expected to follow Serverless convention for naming.
  • services/ Contains each individual Lambda function (.js) and it's definitions (.yml). In addition to the usual handler and event definitions, the yml can also hold a specific resource definition related to the function, without the need for an entry in the resources/ folder.
  • stages/ Stage specific configurations.

Deploy

sls deploy (development) or sls -s production deploy

Webpack

Webpack will automatically bundle only the used dependencies and create a unique and smaller bundle for each function.

Logging

lambda-log provides a more structured way of logging:

const log = require('lambda-log')
log.info('Log Tag', {key1: value1, key2: value2})

Which will result in:

{"_logLevel":"info","msg":"Log Tag","key1":"value1","key2":"value2","_tags":["log","info"]}

You can also add meta data by default:

log.options.meta.fct = 'fctName'
log.options.meta.requestId = event.requestContext.requestId
log.options.meta.path = event.path
log.options.meta.sourceIp = event.requestContext.identity.sourceIp

serverless-template-aws-webpack-nodejs's People

Contributors

danielmuller avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jefdav jmonsanto

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.