Skip to content

Not working on AWS Lambda #1231

@yellowmamba

Description

@yellowmamba

Issue or Feature

I installed prebuilt 2.0 to work with my lambda function. It works locally but when I deploy it to Lambda, it throws the following error from cloudwatch:

module initialization error: Error at Error (native) at Object.Module._extensions..node (module.js:597:18) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (/var/task/node_modules/canvas/lib/bindings.js:3:18

If I understand it correctly from this page. https://github.com/Automattic/node-canvas/wiki/Installation%3A-AWS-Lambda. 2.0 should work out of box, but apparently it doesn't. The example given in this doc indicates the code works with nodejs6.10, so I also tried to run it on nodejs6.10 on Lambda, didn't work. (I initially tried it on nodejs8.10, didn't work either)

Steps to Reproduce

handler.js

const { createCanvas } = require('canvas')
const canvas = createCanvas(200, 200)
const ctx = canvas.getContext('2d')

module.exports.index = function (event, context, callback) {
  console.log(event)
  ctx.font = '30px Impact'
  ctx.fillText('Awesome!', 50, 100)

  callback(null, '<img src="' + canvas.toDataURL() + '" />');
}

serverless.yml

service: my-service

provider:
  name: aws
  runtime: nodejs6.10
  stage: dev
  region: ap-southeast-2

functions:
  index:
    handler: handler.index

package.json

{
  "dependencies": {
    "canvas": "2.0"
  }
}

sls invoke works, but testing directly on Lambda doesn't.

Your Environment

  • Version of node-canvas (e.g. 1.4.0): [email protected]
  • Environment (e.g. node 4.2.0 on Mac OS X 10.8): aws nodejs6.10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions