1

我收到“getEventPrediction”不是函数的错误。我正在关注 AWS 文档,但不知道为什么。

这是我遵循的文档: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/FraudDetector.html

这是我在运行 Lambda 测试事件时遇到的错误:

2020-10-09T21:01:54.151Z a5c86d6f-9347-49ec-9fe9-4124cd976953 错误调用错误 {"errorType":"TypeError","errorMessage":"frauddetector.getEventPrediction 不是函数","stack":[ “TypeError:欺诈检测器.getEventPrediction 不是函数”,“在 Runtime.exports.handler (/var/task/index.js:18:18)”,“在 Runtime.handleOnce (/var/runtime/Runtime.js: 66:25)"]}

这是 Lambda 函数:

    const AWS = require('aws-sdk')
    const frauddetector = new AWS.FraudDetector();
     
    exports.handler = async (event) => {
    
      frauddetector.getDetectors();
      console.log('getDetectors worked 3');
      
      var params = {
          detectorId: 'new_account_fraud_detector',
          eventId:'123456789',
          eventTimestamp: '2020-07-13T23:00:03Z',
          eventTypeName: 'new_customer_registration',
          eventVariables: {'email_address':'fake_jamie11@example.com', 'ip_address':'1.2.3.4'},
          entities: [ {entityType:'customer', entityId:'12345'} ]
      };  
    
      frauddetector.getEventPrediction(params, function (err, data) {
          if (err) console.log(err, err.stack); // an error occurred
          else     console.log(data);           // successful response
      });
      
        // TODO implement
       const response = {
            statusCode: 200,
            body: JSON.stringify('FraudDetector : ran'),
        };
        return response;
    };
4

2 回答 2

0

Lambda 运行时附带的开发工具包不是最新的 Fraud Detector API 更改。

GetEventPrediction 在 2.720.0 中引入:https ://github.com/aws/aws-sdk-js/blob/master/CHANGELOG.md#27200

Lambda 运行时当前使用的是 2.712.0:https ://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

于 2020-10-14T15:10:24.713 回答
0

如果其他人遇到同样的问题,即 lambda 运行时中的 aws-sdk 版本不是最新的,那么按照本文中的建议创建自定义层是一个简单的解决方案:

https://aws.amazon.com/premiumsupport/knowledge-center/lambda-layer-aws-sdk-latest-version/

步骤是:

  • 创建一个新目录并cd进入它
  • npm i aws-sdk
  • 压缩 cwd
  • 运行aws lambda publish-layer-versioncli命令
于 2020-11-11T21:46:49.490 回答