javascriptnode.jstypescriptamazon-s3aws-lambda

Node S3Client Error - input.useDualstackEndpoint is not a function


I'm trying to get a list of files within an S3 folder in a lambda written in typescript. I've added the following dependencies to my package.json.

"@aws-sdk/client-s3": "^3.41.0",
"@aws-sdk/node-http-handler": "^3.40.0",

I then use the S3 client like this:

const client = new S3Client({
    maxAttempts: 3,
    retryMode: 'STANDARD',
    region: getAwsRegion(),
    requestHandler: new NodeHttpHandler({
      connectionTimeout: 3000, // Timeout requests after 3 seconds
      socketTimeout: 5000, // Close socket after 5 seconds
    }),
    credentials: args.credentials,
  });


  const listObjectsCommand = new ListObjectsCommand({
    Bucket: args.bucketName,
    Delimiter: '/',
    Prefix: pathToPartition,
  });
  const objects = await client.send(listObjectsCommand);

I've tried using ListObjectsV2Command as well, but it has the same error. The error is:

TypeError: input.useDualstackEndpoint is not a function\n at Object.getEndpointFromRegion (/var/task/node_modules/<my_module>/node_modules/@aws-sdk/config-resolver/dist-cjs/endpointsConfig/utils/getEndpointFromRegion.js:12:46)\n at processTicksAndRejections (internal/process/task_queues.js:95:5)\n at async Object.serializeAws_restXmlListObjectsCommand (/var/task/node_modules/<my_module>/node_modules/@aws-sdk/client-s3/dist/cjs/protocols/Aws_restXml.js:2386:68)\n at async /var/task/node_modules/<my_module>/node_modules/@aws-sdk/middleware-serde/dist-cjs/serializerMiddleware.js:5:21 .

Any idea what I may be doing wrong?


Solution

  • This happened due to a mismatch is the aws-sdk version used in the package.json I had and the package.json of a dependency. Updating it to be the same version fixed this!