node-newrelic: Error with agent version 9.12.1 and aws-sdk version 3.266.1

Description

The latest release of this agent is causing issues with aws-sdk:

[nuxt] [request error] [unhandled] [500] The request signature we calculated does not match the signature you provided. Check your key and signing method.
  at throwDefaultError (./.output/server/node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:8:22)
  at deserializeAws_restXmlGetObjectCommandError (./.output/server/node_modules/@aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js:4356:51)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async ./.output/server/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
  at async wrappedMiddleware (/usr/local/lib/node_modules/newrelic/node_modules/@newrelic/aws-sdk/lib/v3/smithy-client.js:82:22)
  at async ./.output/server/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:14:20
  at async ./.output/server/node_modules/@aws-sdk/middleware-retry/dist-cjs/retryMiddleware.js:27:46
  at async ./.output/server/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/flexibleChecksumsMiddleware.js:58:20
  at async wrappedHeaderMw (/usr/local/lib/node_modules/newrelic/node_modules/@newrelic/aws-sdk/lib/v3/smithy-client.js:60:12)
  at async ./.output/server/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:5:22

Expected Behavior

Troubleshooting or NR Diag results

Steps to Reproduce

Your Environment

Node version: 18.12.1 New Relic version: 9.12.1 AWS SDK version: 9.266.1

Additional context

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@pawanakhilMM I’ve confirmed the issue you and @marcoswca are seeing with Presigned URLs, since this is a separate issue from this current thread, I’ve opened up newrelic/node-newrelic-aws-sdk#176 to keep things clean/separate, and will do my investigation/fixes off that issue. Thank you again for the report, closing this issue in lieu of newrelic/node-newrelic-aws-sdk#176

@pawanakhilMM thank you so much! i’ll start digging into this

@jmartin4563 We are using With Client and Command approach as per the documentation.

Here is the code snippet.

import { S3, GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';

async generateSignedUrl(
    operation: 'getObject' | 'putObject',
    params: {
      s3Key: string;
      bucketName: string;
      metadata?: { [key: string]: string };
    },
  ): Promise<string> {
       
      const s3Client= new S3({ region: 'us-east-1' });

      let command: GetObjectCommand | PutObjectCommand;

      switch (operation) {
        case 'getObject':
          command = new GetObjectCommand({
            Bucket: params.bucketName,
            Key: params.s3Key,
          });
          break;

        case 'putObject':
          command = new PutObjectCommand({
            Bucket: params.bucketName,
            Key: params.s3Key,
            Metadata: params.metadata,
          });
          break;
      }

      return getSignedUrl(s3Client, command, {
        expiresIn: 18000,
      });
  }

@ahmednaser94 and @atodd I was able to triage and provide a fix. This will go out next week as 9.13.0. In the meantime you can pin newrelic to 9.11.0. If you’re using 3.290.0+ you will need to pin newrelic@9.11.0 but install @newrelic/aws-sdk@5.03 separately.