serverless-webpack: include/exclude not working (trying to include a binary with a function)

This is a Bug Report

Description

Started with the aws-nodejs-typescript template.

I’m trying to include an executable/binary with the function package, so it can be executed on Lambda to do some work there. The binary would be called from within the function as you’d normally call command line binaries on linux.

I tried different variants of include/exclude config params, set individually to false and other tweaks to get the generated package/lambda function to include the binary, but without success.

Am I doing something wrong here, or is it a bug?

serverless.yml

service:
  name: myservice

package:
  individually: true

plugins:
  - serverless-webpack
  - serverless-offline

provider:
  name: aws
  runtime: nodejs6.10
  region: eu-west-1
  memorySize: 1024
  stage: dev


functions:

  processInputFile:
    handler: input-processor/handler.hello
    package:
      include:
        - bin/procbinary
    events:
      - http:
          method: get
          path: render-pdf

File Layout

  • input-processor
    • bin
      • procbinary (my custom executable)
  • node_modules
  • tsconfig.json
  • webpack.config.js
  • package.json
  • serverless.yml

Additional Data

  • Serverless-Webpack Version you’re using: 3.1.0
  • Webpack version you’re using: 3.6.0
  • Serverless Framework Version you’re using: 1.23.0
  • Operating System: macOS 10.12.6 (16G29)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Know this is closed, but kept coming back to this issue when trying to find a solution. I’m using webpack too which results in the binary not being copied.

Install the plugin

npm install --save-dev webpack-plugin-copy

To copy binary add this to webpack.config.js, make sure to include permissions

  plugins: [
    new WebpackPluginCopy([
      {
        from: 'node_modules/rsvg-convert-aws-lambda-binary/vendor/rsvg-convert',
        copyPermissions: true
      }
    ])
  ]

Then to execute the binary

import childProcess from 'child_process';

// some handler logic

childProcess.spawn('./rsvg-convert', params);

Hope that saves someone the 2 hours it took me to figure out 😃

We should handle the per function include in a separate feature request. I will open one later.

@HyperBrain @bastibense I’m not sure what happened, but something went wrong when merging the changes. Just commited again and it should work now. Please update webpack-plugin-copy to 1.0.1

@bastibense, did you figure out how to only copy the binary for a single function? I’ve been trying to solve this for a while now and haven’t been able to get to the bottom of it… 😦

Hi @bastibense , thanks for asking 👍

We had this discussion just recently. The solution that we came up with, is to use the proper webpack plugin (copy file), that will allow to copy files including permissions.

Please read the thread here https://github.com/serverless-heaven/serverless-webpack/issues/205

And the conclusion: https://github.com/serverless-heaven/serverless-webpack/issues/205#issuecomment-331312739

In general, webpack plugins should be used to include specific files (in one or the other way).