Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

headers[headerName].trim is not a function" #1097

Closed
carrickkv2 opened this issue Sep 4, 2023 · 6 comments
Closed

headers[headerName].trim is not a function" #1097

carrickkv2 opened this issue Sep 4, 2023 · 6 comments
Assignees
Labels

Comments

@carrickkv2
Copy link

Describe the bug
When using the middy s3 middleware on AWS, I always get the error below.

{
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "TypeError: headers[headerName].trim is not a function",
    "reason": {
        "errorType": "TypeError",
        "errorMessage": "headers[headerName].trim is not a function",
        "$metadata": {
            "attempts": 1,
            "totalRetryDelay": 0
        },
        "stack": [
            "TypeError: headers[headerName].trim is not a function",
            "    at getCanonicalHeaders (/var/task/src/handlers/event/sendSMS.js:3485:62)",
            "    at SignatureV4.signRequest (/var/task/src/handlers/event/sendSMS.js:3838:80)",
            "    at async /var/task/src/handlers/event/sendSMS.js:4104:18",
            "    at async /var/task/src/handlers/event/sendSMS.js:7736:42",
            "    at async /var/task/src/handlers/event/sendSMS.js:39250:22",
            "    at async /var/task/src/handlers/event/sendSMS.js:1374:26"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: TypeError: headers[headerName].trim is not a function",
        "    at process.<anonymous> (file:///var/runtime/index.mjs:1250:17)",
        "    at process.emit (node:events:513:28)",
        "    at emit (node:internal/process/promises:140:20)",
        "    at processPromiseRejections (node:internal/process/promises:274:27)",
        "    at processTicksAndRejections (node:internal/process/task_queues:97:32)"
    ]
}

I've double checked and all the items I'm passing to fetch data are correct. My function also has the required IAM role.
To me, the error looks like it's from a node module or the AWS client middy is using.

To Reproduce
How to reproduce the behaviour:
Sample code:

import middy from "@middy/core";
import s3 from "@middy/s3";

export const handler = middy((event, context) => {
  try {
    console.log(context);
    console.log(event);
  } catch (error) {
    console.error(error.message);
  }
});

handler.use(
  s3({ fetchData: { config: { Bucket: "sms-templates-test", Key: "templateMessagesSMS.json" } } })
);

Error message:
TypeError: headers[headerName].trim is not a function"

Expected behaviour
s3 Middleware should be used without errors.

Environment:

Node.js: 18
Middy: 4.6.1

@carrickkv2 carrickkv2 added the bug label Sep 4, 2023
@willfarrell
Copy link
Member

willfarrell commented Sep 4, 2023

Internally this middleware does client.send(new GetObjectCommand({ ...options.fetchData[internalKey], ChecksumMode: true })). Which leads me to think it's:
a) AWS SDK out of date, conflicting versions of AWS SDK clients, or regression in the AWS SDK
b) There are extra environmental variable interfering somehow

I not able to reproduce at this moment, are you able to dig a little deeper?

@carrickkv2
Copy link
Author

carrickkv2 commented Sep 4, 2023

Internally this middleware does client.send(new GetObjectCommand({ ...options.fetchData[internalKey], ChecksumMode: true })). Which leads me to think it's: a) AWS SDK out of date, conflicting versions of AWS SDK clients, or regression in the AWS SDK b) There are extra environmental variable interfering somehow

I not able to reproduce at this moment, are you able to dig a little deeper?

I was also thinking this is from the AWS SDK. What version are you using?

I'm using this "aws-sdk": "^2.1425.0",

@willfarrell
Copy link
Member

willfarrell commented Sep 4, 2023

I'm using this "aws-sdk": "^2.1425.0",

The current version of middy only supports v3

@carrickkv2
Copy link
Author

I'm using this "aws-sdk": "^2.1425.0",

The current version of middy only supports v3

Anyway this can be added to the docs?

Final issue is I don't use the SDK anywhere in my code.
The code above is the only code I have.
Does having V2 installed automatically invalidate everything?

@willfarrell
Copy link
Member

Anyway this can be added to the docs?

Install v3 is already in the docs

Does having V2 installed automatically invalidate everything?

I don't think so.

@willfarrell willfarrell self-assigned this Sep 17, 2023
@willfarrell
Copy link
Member

Found the issue, fix will be in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants