Skip to content

Issue between Lambda and DynamoDB

0

Hello,

We create this case because from this day we have an error with our Lambda and our DynamoDB table in several accounts. Yesterday it worked and now we have an error when our Lambda need to interact with the DynamoDB table.

In general we receive a mail from AWS when something change on AWS services that we use and this time we receive nothing. Have you change anything about how it works with DynamoDB (create or update item for example) or with Lambda ? The error that we are facing is the following:

Error : SerializationException: Start of structure or map found where not expected at ProtocolLib.getErrorSchemaOrThrowBaseException (/var/runtime/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js:70:67) at AwsJson1_0Protocol.handleError (/var/runtime/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js:807:65) at AwsJson1_0Protocol.deserializeResponse (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js:597:24) at process.processTicksAndRejections (node:internal/process/task_queues:103:5) at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js:27:24 at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/core/dist-cjs/index.js:119:20 at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js:172:50 at async /var/runtime/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js:119:26 { '$fault': 'client', '$retryable': undefined, '$metadata': { httpStatusCode: 400, requestId: 'ABCD012345', extendedRequestId: undefined, cfId: undefined, attempts: 1, totalRetryDelay: 0 }, __type: 'com.amazon.coral.service#SerializationException' }

Regards

2 Answers
1

This one looks like a client-side serialization problem rather than anything that changed on the DynamoDB side. Two things in the error give it away: the '$fault': 'client' with a 400 status, and the stack trace going through AwsJson1_0Protocol.handleError and the @smithy/core schema/protocol serializer. So the request never really reached DynamoDB in a valid form — the SDK couldn't serialize it and bailed out first. That's also why you didn't get any service notification.

The message Start of structure or map found where not expected basically means the serializer hit an object/map somewhere it expected a different type, most often a list.

Since nothing changed in your own code, I'd start by checking the SDK version. The managed Node.js runtimes ship their own copy of the v3 SDK, and that version gets bumped over time as AWS updates the runtime. The newer serializer is stricter about request shapes, so something that used to go through can now throw SerializationException. I can't say for certain that's what happened here, but comparing the SDK version in your function now vs. before should tell you pretty quickly.

The usual causes for this particular error:

  • Mixing marshalled and unmarshalled input — e.g. sending already-marshalled values like { S: "value" } into DynamoDBDocumentClient, or sending plain objects to the low-level DynamoDBClient without marshall(). Best to stick to one.
  • A field that should be a list being passed as an object (or the reverse).
  • undefined or empty values sneaking into Item, Key, or ExpressionAttributeValues.

A couple of things that tend to help: log the exact params going into the command and diff them against the API reference field by field, and consider bundling @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb in your package (or a layer) and pinning them in package.json so the runtime's SDK version isn't controlling behavior for you.

Some references:

AWS

answered 21 days ago

EXPERT

reviewed 20 days ago

0

The SerializationException error you're encountering typically indicates a data format mismatch when your Lambda function is attempting to write to or read from DynamoDB. This error occurs when the data structure being sent doesn't match what DynamoDB expects.

Common causes for this issue include:

  1. Incorrect data type formatting: DynamoDB requires items to be formatted with explicit type descriptors (e.g., {'S': 'string_value'} for strings, {'N': 'number_value'} for numbers). If you're sending plain JavaScript objects without these type descriptors, you'll encounter serialization errors.

  2. Malformed item structure: The item being written may contain nested structures or data types that aren't properly formatted for DynamoDB's expected schema.

  3. SDK version or code changes: If there were recent updates to your Lambda function code or dependencies, there may have been unintentional changes to how data is being structured before sending to DynamoDB.

To troubleshoot this issue:

  • Review your Lambda function code to ensure all DynamoDB operations are formatting data correctly with proper type descriptors
  • Verify that any data transformations or JSON parsing are producing the expected structure
  • Check if there were any recent deployments or code changes to your Lambda functions
  • Add logging to capture the exact data structure being sent to DynamoDB before the put_item or update_item call
  • Ensure your Lambda function has the necessary IAM permissions to interact with DynamoDB

If you need further assistance with your specific case, please add correspondence through the AWS Support Center at https://console.aws.amazon.com/support/ with additional details about your Lambda function code and the specific DynamoDB operations being performed.
Sources
Using Lambda functions in AWS SAM and Infrastructure Composer - AWS Lambda

answered 21 days ago

AWS
SUPPORT ENGINEER

reviewed 21 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.