Git Product home page Git Product logo

serverless-azure-webpack-sample's Introduction

Serverless Azure Webpack Sample

Summary

This is a small template project that demonstrates the combined usage of serverless-azure-functions with serverless-webpack. Serverless Azure Functions is a plugin for the Serverless Framework that can help you quickly deploy code to Microsoft Azure Functions. Serverless Webpack will help to bundle that code into a single file for deployment. If you're new to Serverless Azure Functions, you should look at their quick start guide.

Webpack is important on the Microsoft Azure platform because Azure Functions can be slow to load many small files (such as the node_modules directory). If you bundle everything with webpack, you can significantly reduce the cold start time.

How to install

  1. Download a copy of this repository
  2. If you haven't already, install Node.js and the Serverless Framework.
  3. Enter the local repository directory and run npm install to install the project dependencies.
  • The project dependencies include serverless-azure-functions and serverless-webpack.
  1. If you don't already have one, create a Microsoft Azure account as described in the "Quick Start" section of the guide.
  2. In the local ./credentials directory, copy the template.sh file and fill in the values according to the Azure Credentials guide found here.
  • This file will be used to export env vars that allow uploads to your Azure account. You will need to run source credentials/<your-account>.sh only when you open a new terminal tab.
  • If running Windows, the PowerShell equivalent can be found at the same link above.
  1. Now you're all set to deploy.
  • Run sls deploy and Serverless will set up the Function App for you.
  • Run sls invoke -f hello to make sure it's working.
  1. Hack away! Modify and expand the code to suit your needs.

Architecture

Folder Structure

The repository contains only one service, with a directory for each function that the service deploys. The functions do not do much; they are just for demonstration. There is also a "common" folder for code that can be used by more than one function.

Each function directory has its own index.js file, which exports a handler() function that is used as an entrypoint (defined in serverless.yml). By keeping the entrypoints in separate files, Serverless Webpack is able to bundle the code for each function independently, even if it is imported from "common".

This folder structure is relatively simple at the moment, but it could easily be expanded to support multiple services in the same project.

Packaging

Babel is used to compile next-generation JavaScript to more broadly compatible code. Webpack bundles the code imported from multiple files into a single deployment file. The source-map is used to keep the line numbers for debugging. Serverless then uploads the code (in a zip file) to the Azure servers and it is run from there.

Logging

You can use sls logs -f <function-name> to stream the logs of the passed function when it is executed. Anything logged with context.log.info() will show up there.

serverless-azure-webpack-sample's People

Contributors

kosnire avatar

Watchers

 avatar

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.