serverless-scaleway-functions icon indicating copy to clipboard operation
serverless-scaleway-functions copied to clipboard

Error using dependencies in functions

Open gaedlld opened this issue 4 years ago • 3 comments

Hello there,

I'm trying to use a NodeJS14 Scaleway Functions to add features to a Scaleway Object Storage bucket. But, I can't find the way to use needed dependencies in my function...

When I initiate my two dependencies in the code, like this :

const AWS = require('aws-sdk');
const Sharp = require('sharp');

After installed both dependencies with npm install aws-sdk sharp, and getting the package.json's dependencies part correctly filled.

I got this response (after deployment) when I try to fetch the function over http :

An error occured during handler execution: Function Handler does not exist, check that you provided the right HANDLER parameter (path to your module with exported function to use)

However, without both import lines, the function is correctly working !

Could you help me please ?

Here my first test function :

const AWS = require('aws-sdk');
const Sharp = require('sharp');

module.exports.handle = (event, context, callback) => {

  const photoId = event.queryStringParameters.id;
  const size = event.queryStringParameters.size;

  const result = {
    message: 'Hello from Serverless Framework and Scaleway Functions :D',
    photoId: photoId,
    size: size
  };
  const response = {
    statusCode: 200,
    body: JSON.stringify(result),
  };

  return response;
};

And the corresponding serverless.yml :

service:
  name: MyFunctions
configValidationMode: off
provider:
  name: scaleway
  runtime: node14
  scwToken: '***'
  scwOrganization: '***'

plugins:
  - serverless-scaleway-functions

package:
  exclude:
    - .gitignore
    - .git/**
    - node_modules/**

functions:
  first:
    handler: handler.handle
    env:
      ACCESS_KEY: '***'
      SECRET_KEY: '***'
      BUCKET: '***'

gaedlld avatar May 27 '21 09:05 gaedlld

Hello, did you try by removing the node_modules/** from your package.exclude list ?

almottier avatar May 27 '21 13:05 almottier

I added it because without I got an error at deployment ( Serverless: Uploading source code... ) :

Error [ERR_FR_MAX_BODY_LENGTH_EXCEEDED]: Request body larger than maxBodyLength limit

gaedlld avatar May 27 '21 15:05 gaedlld

Did you get this to work ?

RupertBarrow avatar Feb 04 '22 19:02 RupertBarrow