Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InvalidParameterType: Expected params.ExpressionAttributeValues[':et1'].N to be a string

Here is my code that I'm using for making queries:

var scanParams = {
        TableName : 'xxxx',
        FilterExpression : '( (event = :e0) AND (event = :e1 AND eventTime > :et1 AND eventTime < :et2) )',
        ExpressionAttributeValues: { 
          ':e0': { S: 'ME 21' },
          ':e1': { S: 'ME 21' },
          ':et1': { N: 1509267218 },
          ':et2': { N: 1509353618 } 
        },
        ProjectionExpression: "event, customer_id, visitor",
    };

In configuration of the respective dynamodb table it seems like I've added Nummber for eventTime column.

enter image description here

Here is the error:

error happened  { MultipleValidationErrors: There were 2 validation errors:
* InvalidParameterType: Expected params.ExpressionAttributeValues[':et1'].N to be a string
* InvalidParameterType: Expected params.ExpressionAttributeValues[':et2'].N to be a string
    at ParamValidator.validate (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/param_validator.js:40:28)
    at Request.VALIDATE_PARAMETERS (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/event_listeners.js:125:42)
    at Request.callListeners (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at callNextListener (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at /home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/event_listeners.js:85:9
    at finish (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/config.js:315:7)
    at /home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/config.js:333:9
    at SharedIniFileCredentials.get (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/credentials.js:126:7)
    at getAsyncCredentials (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/config.js:327:24)
    at Config.getCredentials (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/config.js:347:9)
    at Request.VALIDATE_CREDENTIALS (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/event_listeners.js:80:26)
    at Request.callListeners (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/sequential_executor.js:101:18)
    at Request.emit (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at Request.runTo (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/request.js:403:15)
    at /home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/request.js:791:12
    at Request.promise (/home/jahidul/workspace/backstage-opticon/node_modules/aws-sdk/lib/request.js:777:12)
    at DynamoDBService.scanItem (/home/jahidul/workspace/backstage-opticon/shared/services/dynamodb/dynamodb.service.ts:52:39)
    at /home/jahidul/workspace/backstage-opticon/job-scripts/dyno-test.js:57:12
    at sailsReady (/home/jahidul/workspace/backstage-opticon/node_modules/sails/lib/app/lift.js:49:12)
    at /home/jahidul/workspace/backstage-opticon/node_modules/async/lib/async.js:251:17
    at /home/jahidul/workspace/backstage-opticon/node_modules/async/lib/async.js:154:25
    at /home/jahidul/workspace/backstage-opticon/node_modules/async/lib/async.js:248:21
    at /home/jahidul/workspace/backstage-opticon/node_modules/async/lib/async.js:612:34

Any idea? Thanks in advance.

like image 696
MD. Jahidul Islam Avatar asked Feb 17 '26 21:02

MD. Jahidul Islam


1 Answers

Use the parameter below:

var scanParams = {
        TableName : 'xxxx',
        FilterExpression : '( (event = :e0) AND (event = :e1 AND eventTime > :et1 AND eventTime < :et2) )',
        ExpressionAttributeValues: { 
          ':e0': { "S": "ME 21" },
          ':e1': { "S": "ME 21" },
          ':et1': { "N": "1509267218" },
          ':et2': { "N": "1509353618" } 
        },
        ProjectionExpression: "event, customer_id, visitor",
    };

In Dynamo DB, the type (Number) is represented by "N" and the value must be in string format "1509353618". Hope this will resolve your problem.

like image 125
Sowvik Roy Avatar answered Feb 21 '26 14:02

Sowvik Roy