Что означает «errorType»: «string» в AWS Lambda? - PullRequest
2 голосов
/ 18 апреля 2020

В настоящее время я пытаюсь протестировать лямбда-функцию, используя схему cognito-syn c -trigger. Я добавил свой собственный код функции без ошибок, однако, когда я тестирую его, я получаю Результат выполнения: сбой

Это результаты из подробностей журнала

{
  "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    

Мой код для лямбда-потехи c выглядит следующим образом.

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
}

Если бы кто-нибудь мог направить меня в правильном направлении относительно того, почему я получаю эту ошибку, это было бы очень ценно.

Ответы [ 2 ]

1 голос
/ 20 апреля 2020

Я не являюсь пользователем Node, но из документации 1011 * Node SDK следует, что вам нужно указать тип добавляемых параметров, например:

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
  }
};
0 голосов
/ 20 апреля 2020

Вы можете использовать DynamoDB DocumentClient экземпляр вместо DynamoDB, вам не нужно определять тип каждого атрибута.

Заменить

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

на

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