1

I am writing services with Serverless Framework & Azure Functions. Examples out there are very simple. But when I try to take a step further, I run into problem. Currently learning from AWS Lambda and then trying to implement it on Azure Functions.

The goal of doing so is:

1) Implement functions as es6 classes and then building the project with webpack.

2) Find a right project structure, which makes more sense.

3) Follow SoC pattern.

I have created a github project https://github.com/GeekOnGadgets/serverless-azure-settings and when I try to build this project serverless package it creates .serverless folder and inside it there is .zip file (the compiled version). Which I understand gets deployed to azure when you run serverless deploy. But when I check on Azure the function is just development code and not the compiled one (please refer to the code below).

Can someone please help with this. Any suggestions is appreciated.

import Settings from './src/Settings/Settings'

module.exports.settings = (event, context, callback) => {
    let settings = new Settings();

    const response = {
        statusCode: 200,
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify(settings.dev()),
    };
    callback(null, response);
}
Zanon
  • 22,850
  • 18
  • 101
  • 110
GeekOnGadgets
  • 911
  • 3
  • 13
  • 43
  • with js it is mostly bundling and the compilation happens in the client side/ browser. as far as azure functions are concerned am not sure if you need to bundle them and create buildpacks. they are simple functions you build . – Aravind May 03 '17 at 07:51

2 Answers2

0

Indeed javascript azure functions run on nodejs so commonjs modules are the natural format. Node also natively supports much of ES6, though the Functions version of node might not be the latest.

however, there is a current speed issue with loading all the dependencies in node_modules. This is due to file access so a workaround exists to bundle everything into a single script which package.json -> main points to.

I cant comment on how that fits in with serverless, but perhaps this will help clarify.

Steve Lee
  • 2,451
  • 3
  • 14
  • 18
0

As far as I know, Node.js still does not support import/export ES6 syntax for modules. See also here.

Try a new deploy changing from

import Settings from './src/Settings/Settings'

to

const Settings = require('./src/Settings/Settings')
Community
  • 1
  • 1
Zanon
  • 22,850
  • 18
  • 101
  • 110