简体   繁体   English

AWS Lambda 节点模块版本不匹配

[英]AWS Lambda Node module version mismatch

I was following the AWS Lambda tutorial on automating deployments of Lambda-based applications and have uploaded a simple lambda function to AWS via CodePipeline and CloudFormation, but am getting the following error while trying to run my lambda function:我正在关注有关自动部署基于 Lambda 的应用程序的 AWS Lambda 教程,并通过 CodePipeline 和 CloudFormation 将一个简单的 lambda 函数上传到 AWS,但是在尝试运行我的 lambda 函数时遇到以下错误:

{
  "errorMessage": "Module version mismatch. Expected 48, got 46.",
  "errorType": "Error",
  "stackTrace": [
    "Object.Module._extensions..node (module.js:597:18)",
    "Module.load (module.js:487:32)",
    "tryModuleLoad (module.js:446:12)",
    "Function.Module._load (module.js:438:3)",
    "Module.require (module.js:497:17)",
    "require (internal/module.js:20:19)",
    "bindings (/var/task/node_modules/bindings/bindings.js:81:44)",
    "Object.<anonymous> (/var/task/node_modules/time/index.js:8:35)",
    "Module._compile (module.js:570:32)"
  ]
}

The contents of my lambda function are as follows...我的 lambda 函数的内容如下...

samTemplate.yaml samTemplate.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Outputs the time
Resources:
  TimeFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs6.10
      CodeUri: ./
      Events:
        MyTimeApi:
          Type: Api
          Properties:
            Path: /TimeResource
            Method: GET

buildspec.yml构建规范.yml

version: 0.1
phases:
  install:
    commands:
      - npm install time
      - aws cloudformation package --template-file samTemplate.yaml --s3-bucket <redacted> 
                                   --output-template-file NewSamTemplate.yaml
artifacts:
  type: zip
  files:
    - NewSamTemplate.yaml

and index.js和 index.js

var time = require('time');
exports.handler = (event, context, callback) => {
    var currentTime = new time.Date(); 
    currentTime.setTimezone("America/Los_Angeles");
    callback(null, {
        statusCode: '200',
        body: 'The time in Los Angeles is: ' + currentTime.toString(),
    });
};

On the AWS page of the Lambda function I do have NodeJS 6.10 set as the runtime, so I'm confused why I'm getting this error.在 Lambda 函数的 AWS 页面上,我确实将 NodeJS 6.10 设置为运行时,所以我很困惑为什么会收到此错误。 Any ideas?有什么想法吗?

I found the problem.我发现了问题。 In the build step, I was using Node v4 (by the tutorial's guidance) when it should have been v6.在构建步骤中,我使用了 Node v4(根据教程的指导),而它应该是 v6。 Check your build step matches the Node version your lambda function is using!检查您的构建步骤是否与您的 lambda 函数使用的 Node 版本匹配!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模块版本不匹配 - Module version mismatch 结合使用节点请求模块和AWS Lambda和API网关 - Using the Node Request module with AWS Lambda and API Gateway 如何在 AWS Lambda function 中连接 node-imap 模块 - How to connect node-imap module inside AWS Lambda function 节点模块“angular2-multiselect-dropdown”的元数据版本不匹配错误 - ERROR in Metadata version mismatch for module for the node module "angular2-multiselect-dropdown " 在异步 AWS Lambda 函数中使用带有 node-fetch 模块的 node.js 时遇到问题 - trouble using node.js w/ node-fetch module in async AWS Lambda Function 模块/node_modules/time-ago-pipe/time-ago-pipe.d.ts的元数据版本不匹配,找到了版本4,预期为3 - Metadata version mismatch for module /node_modules/time-ago-pipe/time-ago-pipe.d.ts, found version 4, expected 3 AWS Lambda函数出现节点问题 - AWS Lambda function with Node issue AWS Lambda 节点处理问题 - AWS Lambda Node processing issue 错误:找到版本4的模块的元数据版本不匹配,预期为3 - Error: Metadata version mismatch for module found version 4, expected 3 Webpack和AWS Lambda问题 - 模块上缺少处理程序 - Webpack and AWS Lambda issue - handler missing on module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM