Serverless Lambda deployment in node8.10 not uploading any code

414 views Asked by At

I have a lambda function deployed with Serverless. It was deployed with node6.10 runtime, so I decided to redeploy the service with the node8.10 runtime instead.

However after making this redeploy I faced a strange issue where I could not invoke the function and could no longer deploy updates to the function as the filesize was too large (60mb+). I was able to resolve this by uninstalling and reinstalling serverless-plugin-optimize.

This solved the file size issue (now it's about 2mb) but I still cannot invoke the function. Attempting to invoke it yields the following log in CloudWatch:

Unable to import module 'lambda/index': Error
  at Function.Module._resolveFilename (module.js:547:15)
  at Function.Module._load (module.js:474:25)
  at Module.require (module.js:596:17)
  at require (internal/module.js:11:18)

My expectation then was that the file path in my serverless.yml for the function was wrong, or that it was not exporting correctly.

./serverless.yml

functions:
  funcOne:
    handler: lambda/index.handler

./lambda/index.js

exports.handler = function (event, context) {

// execution code

};

However this does not appear to be the case, I know this because setting debug: true for the serverless-plugin-optimize leaves behind the _optimize folder with my minified code in. However somehow despite it being present locally it seems it is not making the upload to Lambda.

Viewing this in the AWS console I get the following:

2.6mb upload listed in Lambda directory:

2.6mb upload listed in Lambda directory

Error in Lambda console code editor Could not open file: /lambda/index.js

60mb file still listed in S3 deployment bucket 60mb file still listed in S3 deployment bucket

I can't explain why I am getting this issue or what about switching to node8.10 would cause it. Outside of the serverless.yml file none of the code has been changed from the working node6.10 version. Has anyone encountered this issue before or knows of anything that might fix it?

1

There are 1 answers

0
Josh On BEST ANSWER

I have now successfully resolved this issue. I don't know why this was the case, but the problem seemed to be with deploying to node8.10 using an older version of Serverless (1.27.2). Upgrading to the latest version of Serverless (1.32.0) fixed it immediately.