【问题标题】:What does a "errorType": "string" mean in AWS Lambda?AWS Lambda 中的“errorType”:“string”是什么意思?
【发布时间】:2022-03-02 19:20:00
【问题描述】:

我目前正在尝试使用 cognito-sync-trigger 蓝图测试 lambda 函数。我添加了自己的函数代码,没有错误,但是当我测试它时,我得到 Execution result: failed

这是来自日志详细信息的结果

{
  "errorType": "string",
  "errorMessage": "{\"datasetName\":\"googleUserData\",\"eventType\":\"SyncTrigger\",\"region\":\"us-east-1\",\"identityId\":\"us-east-1:1a8870db-2510-4c42-a1d5-6e895bb52040\",\"datasetRecords\":{\"name\":{\"newValue\":\"amishra2\",\"oldValue\":\"amishra\",\"op\":\"replace\"},\"email\":{\"newValue\":\"amishra2@asmtechnology.com\",\"oldValue\":\"amishra@asmtechnology.com\",\"op\":\"replace\"}},\"identityPoolId\":\"us-east-1:3a7a90d7-b0e7-4730-b0aa-866c9a16ec85\",\"version\":2}",
  "trace": []
}

日志输出

aws-sdk/lib/param_validator.js:34:10)
        at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:126:42)
        at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20) {
      message: "Unexpected key '8' found in params.Item['email_address']",
      code: 'UnexpectedParameter',
      time: 2020-04-18T20:37:52.408Z
    },
    UnexpectedParameter: Unexpected key '9' found in params.Item['email_address']
        at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)
        at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:77:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
        at ParamValidator.validateMap (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:117:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:92:21)
        at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
        at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)
        at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:126:42)
        at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20) {
      message: "Unexpected key '9' found in params.Item['email_address']",
      code: 'UnexpectedParameter',
      time: 2020-04-18T20:37:52.408Z
    },
    UnexpectedParameter: Unexpected key '10' found in params.Item['email_address']
        at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)
        at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:77:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
        at ParamValidator.validateMap (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:117:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:92:21)
        at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
        at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)
        at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:126:42)
        at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20) {
      message: "Unexpected key '10' found in params.Item['email_address']",
      code: 'UnexpectedParameter',
      time: 2020-04-18T20:37:52.408Z
    },
    UnexpectedParameter: Unexpected key '11' found in params.Item['email_address']
        at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)
        at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:77:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
        at ParamValidator.validateMap (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:117:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:92:21)
        at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)
        at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
        at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validatorEND RequestId: cf0d5cfd-29a0-434d-817b-93bf4328961a
REPORT RequestId: cf0d5cfd-29a0-434d-817b-93bf4328961a  Duration: 346.12 ms Billed Duration: 400 ms Memory Size: 128 MB Max Memory Used: 82 MB  Init Duration: 362.75 ms    

我的 lambda func 代码如下。

var AWS = require('aws-sdk');

AWS.config.update({region: 'us-east-1'});


    exports.handler = function(event, context, callback) {

        if (event.eventType !=='syncTrigger'){

            callback(JSON.stringify(event));
        }
        if (!(('name' in event.datasetRecords) && ('email' in event.datasetRecords))){
            callback(JSON.stringify(event));
        }
        var name = event.datasetRecords.name.newValue;
        var email = event.datasetRecords.email.newValue;

        var shouldDeleteRecord = (event.datasetRecords.name.op === 'remove') || (event.datasetRecords.email.op === 'remove');

        if (shouldDeleteRecord === true) {
            // do not delete from dynamo DB
            callback(null, event);
        }
       // var db = new doc.DynamoDB();
        var db = new AWS.DynamoDB({apiVersion: '2012-08-10'});
        var params = {'TableName' : 'User', 
    'Item': {'id' : event.identityId, 'username' : name, 'email_address': email}};

        db.putItem(params,function(err, data) {
            if (err) {
                console.log('User insert failure', err);
                callback(err);
            } else {
                console.log('User insert success', data);
                callback(null, event);
            }
        });
    }

这里是测试事件代码

{
  "datasetName": "googleUserData",
  "eventType": "SyncTrigger",
  "region": "us-east-1",
  "identityId": "us-east-1:1a8870db-2510-4c42-a1d5-6e895bb52040",
  "datasetRecords": {
    "name": {
      "newValue": "amishra2",
      "oldValue": "amishra",
      "op": "replace"
    },
    "email": {
      "newValue": "amishra2@asmtechnology.com",
      "oldValue": "amishra@asmtechnology.com",
      "op": "replace"
    }
  },
  "identityPoolId": "us-east-1:3a7a90d7-b0e7-4730-b0aa-866c9a16ec85",
  "version": 2
}

如果有人能引导我了解我为什么会收到此错误,我将不胜感激。

【问题讨论】:

    标签: node.js amazon-web-services aws-lambda amazon-dynamodb


    【解决方案1】:

    我不是 Node 用户,但从 AWS Node SDK documentation 看来,您需要指定要添加的参数的类型,如下所示:

    var params = {
      Item: {
       "AlbumTitle": {
         S: "Somewhat Famous"
        }, 
       "Artist": {
         S: "No One You Know"
        }, 
       "SongTitle": {
         S: "Call Me Today"
        }
      }, 
      ReturnConsumedCapacity: "TOTAL", 
      TableName: "Music"
     };
    

    您的代码似乎没有S: 位:

    var params = {
      'TableName' : 'User', 
      'Item': {
        'id' : event.identityId,
        'username' : name,
        'email_address': email
      }
    };
    

    【讨论】:

      【解决方案2】:

      您可以使用DynamoDB DocumentClient 实例代替DynamoDB 实例,您无需定义每个属性的类型。

      替换

      var db = new AWS.DynamoDB({apiVersion: '2012-08-10'});
      

      var db = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});
      

      【讨论】:

        【解决方案3】:

        在我的情况下,你可以试试这个。

        回调(null,event);

        【讨论】:

        • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
        猜你喜欢
        • 1970-01-01
        • 2021-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多