简体   繁体   中英

How to fix nodejs version issue in Aws-lambda function

I am trying to resize my images with the help of Aws lambda and getting error and i am following this article

https://aws.amazon.com/blogs/compute/resize-images-on-the-fly-with-amazon-s3-aws-lambda-and-amazon-api-gateway/

{
  "errorType": "Error",
  "errorMessage": "The module '/var/task/node_modules/sharp/build/Release/sharp.node'\nwas compiled against a different Node.js version using\nNODE_MODULE_VERSION 48. This version of Node.js requires\nNODE_MODULE_VERSION 64. Please try re-compiling or re-installing\nthe module (for instance, using `npm rebuild` or `npm install`).",
  "trace": [
    "Error: The module '/var/task/node_modules/sharp/build/Release/sharp.node'",
    "was compiled against a different Node.js version using",
    "NODE_MODULE_VERSION 48. This version of Node.js requires",
    "NODE_MODULE_VERSION 64. Please try re-compiling or re-installing",
    "the module (for instance, using `npm rebuild` or `npm install`).",
    "    at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)",
    "    at Module.load (internal/modules/cjs/loader.js:600:32)",
    "    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:531:3)",
    "    at Module.require (internal/modules/cjs/loader.js:637:17)",
    "    at require (internal/modules/cjs/helpers.js:22:18)",
    "    at Object.<anonymous> (/var/task/node_modules/sharp/lib/constructor.js:8:15)",
    "    at Module._compile (internal/modules/cjs/loader.js:701:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)",
    "    at Module.load (internal/modules/cjs/loader.js:600:32)"
  ]
}

Steps to fix it: -

  1. Download your project(function) form AWS Lambda using Action->Export function and unzip it.

在此处输入图片说明

  1. Install Latest version of node in your local system(say node 8.10.0). You can see i already have 8.10.0.

在此处输入图片说明

  1. Go to your unzipped project folder via terminal and type

    npm rebuild

在此处输入图片说明

  1. After this again zip this project and uplaod it on AWS Lambda and select the node runtime one you updated with (suppose it is node 8.10.0 then select runtime in aws lambda function runtime as node 8.10x).

Hope it helps.

Thanks

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