DynamoDB shell returns items - lambda not

Hello, when running a scan operation, the web based shell returns many items. When I run the same query within the javascript lambda function, the items are empty (please find the output below). You can see three requests with the lambda function for DynamoDB, since the EvaluatedKey is added to search all of the items. The requests are identical, but the response are very different.

DynamoDB JavaScript shell via localhost:8000/shell (without EvaluatedKey)
Request

var params = {
  TableName: 'schools',
  FilterExpression: '#school_name = :value',
  ExpressionAttributeNames: { '#school_name': 'name' },
  ExpressionAttributeValues: { ':value': { S: 'School 1' } }
};
dynamodb.scan(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

Response

{ Items: [............],
  Count: 74,
  ScannedCount: 74,
  LastEvaluatedKey: { id: '6fcbcaf8-d4fc-4484-a74f-7ce9b18cbc6f' } }

Lamda parameters for DynamoDB
1. Request

{ TableName: 'schools',
  FilterExpression: '#school_name = :value',
  ExpressionAttributeNames: { '#school_name': 'name' },
  ExpressionAttributeValues: { ':value': { S: 'School 1' } } }

1. Response

{ Items: [],
  Count: 0,
  ScannedCount: 74,
  LastEvaluatedKey: { id: '6fcbcaf8-d4fc-4484-a74f-7ce9b18cbc6f' } }

2. Request

{ TableName: 'schools',
  FilterExpression: '#school_name = :value',
  ExpressionAttributeNames: { '#school_name': 'name' },
  ExpressionAttributeValues: { ':value': { S: 'School 1' } },
  ExclusiveStartKey: { id: '6fcbcaf8-d4fc-4484-a74f-7ce9b18cbc6f' } }

2. Response

{ Items: [],
  Count: 0,
  ScannedCount: 23,
  LastEvaluatedKey: { id: '6fcbcaf8-d4fc-4484-a74f-7ce9b18cbc6e' } }

3. Request

{ TableName: 'schools',
  FilterExpression: '#school_name = :value',
  ExpressionAttributeNames: { '#school_name': 'name' },
  ExpressionAttributeValues: { ':value': { S: 'School 1' } },
  ExclusiveStartKey: { id: '6fcbcaf8-d4fc-4484-a74f-7ce9b18cbc6e' } }

3. Response

{ Items: [], Count: 0, ScannedCount: 3 }

No one has experienced something like that? Is it a bug on the dynamodb side?

Everything else being equal I would look your IAM permissions and make sure your Lambda has sufficient privileges to access the data.

I am running locally, that is why I am so confused. Running the same query in the lambda function via sls offline start returns 0 items. Running the same query within the webbased shell for serverless-dynamodb-local returns all the elements it should. Any ideas? :thinking:

Sorry, Iā€™m not using serverless-dynamodb-local.

I have experienced similar issues recently, make sure your region is correct

1 Like

Setting the region solved the issue. Thank you!