简体   繁体   中英

Serverless Framework with Azure functions

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);
}

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.

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM