Skip to content

Invalid character in header content [\"user-agent\"] when using ScanCommand from client-dynamodb #6943

Open
@verebes1

Description

@verebes1

Checkboxes for prior research

Describe the bug

One of our services has been brought down because of a change in the AWS-SDK. We have been using the "@aws-sdk/client-dynamodb" to instantiate a client:

const client = new DynamoDBClient({maxAttempts: 10});
this.docClient = DynamoDBDocumentClient.from(client);

In the code we were creating a ScanCommand that was retrieving all ids of items from a given DB. This code has been functioning fine without any issue up until 13-March-2025 when there was an autoredeployment of the lambda that updates connection certificates (so no code changes) This has broke our lambdas completely and we started getting the following error.

{
    "errorType": "TypeError",
    "errorMessage": "Invalid character in header content [\"user-agent\"]",
    "code": "ERR_INVALID_CHAR",
    "$metadata": {
        "attempts": 1,
        "totalRetryDelay": 0
    },
    "stack": [
        "TypeError [ERR_INVALID_CHAR]: Invalid character in header content [\"user-agent\"]",
        "    at ClientRequest.setHeader (node:_http_outgoing:658:3)",
        "    at new ClientRequest (node:_http_client:293:14)",
        "    at request (node:https:381:10)",
        "    at /var/task/node_modules/@smithy/node-http-handler/dist-cjs/index.js:366:19",
        "    at new Promise (<anonymous>)",
        "    at _NodeHttpHandler.handle (/var/task/node_modules/@smithy/node-http-handler/dist-cjs/index.js:300:12)",
        "    at async /var/task/node_modules/@smithy/middleware-serde/dist-cjs/index.js:33:24",
        "    at async /var/task/node_modules/@smithy/core/dist-cjs/index.js:167:18",
        "    at async /var/task/node_modules/@smithy/middleware-retry/dist-cjs/index.js:321:38",
        "    at async /var/task/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22"
    ]
}

After having a call with AWS Support and testing multiple solutions. The only solution that worked was to add the AWS SDK as a node-module to the lambda package and pin it down to an older version specifically:

        "@aws-sdk/client-cloudwatch": "3.658.0",
        "@aws-sdk/client-dynamodb": "3.658.0",
        "@aws-sdk/client-sqs": "3.658.0",
        "@aws-sdk/lib-dynamodb": "3.658.0",
        "@aws-sdk/types": "3.654.0",

Any version post that one creates the same issue
The error message seems to come from one of the aws-sdk dependencies. We have managed to pinpoint the exact line of code that fails with that error and it is the one which sends the scancommand using the docClient.

await this.docClient.send(command);

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/client-dynamodb@3.767.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

20.x

Reproduction Steps

Just send a ScanCommand to the DB using the latest package version and a Node 20.x runtime.
I am happy to provide more context if needed but this would have to be on a private call with AWS Support

Observed Behavior

{
    "errorType": "TypeError",
    "errorMessage": "Invalid character in header content [\"user-agent\"]",
    "code": "ERR_INVALID_CHAR",
    "$metadata": {
        "attempts": 1,
        "totalRetryDelay": 0
    },
    "stack": [
        "TypeError [ERR_INVALID_CHAR]: Invalid character in header content [\"user-agent\"]",
        "    at ClientRequest.setHeader (node:_http_outgoing:658:3)",
        "    at new ClientRequest (node:_http_client:293:14)",
        "    at request (node:https:381:10)",
        "    at /var/task/node_modules/@smithy/node-http-handler/dist-cjs/index.js:366:19",
        "    at new Promise (<anonymous>)",
        "    at _NodeHttpHandler.handle (/var/task/node_modules/@smithy/node-http-handler/dist-cjs/index.js:300:12)",
        "    at async /var/task/node_modules/@smithy/middleware-serde/dist-cjs/index.js:33:24",
        "    at async /var/task/node_modules/@smithy/core/dist-cjs/index.js:167:18",
        "    at async /var/task/node_modules/@smithy/middleware-retry/dist-cjs/index.js:321:38",
        "    at async /var/task/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22"
    ]
}

Expected Behavior

Retrieval of the item's ids from a Dynamo DB table

Possible Solution

Pin down the packages to these:

        "@aws-sdk/client-cloudwatch": "3.658.0",
        "@aws-sdk/client-dynamodb": "3.658.0",
        "@aws-sdk/client-sqs": "3.658.0",
        "@aws-sdk/lib-dynamodb": "3.658.0",
        "@aws-sdk/types": "3.654.0",

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.investigatingIssue is being investigated and/or work is in progress to resolve the issue.p2This is a standard priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions