getSignedUrl from @aws-sdk/s3-request-presigner doesn't return

0

In my nodejs service I've a function like this one

...
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3'
...
async getPreSignedUrl(Key: string, Bucket: string): Promise<string> {
    try {
      const command = new GetObjectCommand({ Key, Bucket })
      await this.s3Client.send(command)

     this.logger.log(`Before`) <----- I can see this

      const signedUrl = await getSignedUrl(this.s3Client, command, {
        expiresIn: this.configService.get('AWS_PRESIGNED_URL_EXPIRATION_SECONDS', 300),
      })

      this.logger.log(`Pre signed url: ${signedUrl}`) <----- never reach this point
      return signedUrl
    } catch (error) {
      this.logger.error(
        `Error while retrieving pre signed url from AWS for object ${Key} and bucket ${Bucket}. Error details: ${JSON.stringify(
          error,
        )}`,
      )
      throw error
    }
  }

Regularly happens that getSignedUrl never return and the caller stay there waiting for something...
If I restart the pod (where the service lives), the application start to work fine. After a while, after some hours, again same behaviour. No error caught, nothing in the application log...
I enabled server access logging and cloud trail data events, but nothing there for that call. What would you do to make a step toward a solution?

Luca
已提问 8 个月前379 查看次数
1 回答
1

The request to "getSignedUrl" seems to hang and not return at all. To troubleshoot further, you can try to:

  1. Check if the log timestamp in "application log", "S3 Server access log" and "Cloudtrail data events" matches. This can help to find out till what point does the request passes through and where it's getting stuck.
  2. Check if there are any network-related issues (firewall or network configuration) between your application and AWS S3.
  3. Check if there's any memory leak or resource exhaustion in the pod where your application is deployed. (This could be possible since the application is working fine when the service is restarted.)
  4. Try implementing a "Retry or Timeout" mechanism in the code to see if that resolves the issue.
profile picture
已回答 8 个月前
  • Thank you for the answer. The only think I didn't try yet is the second point even though I don't understand how it's possible to have regularly this problem.

  • It's unusual to experience such issues regularly if everything seems correctly configured. Please give more context about your existing deployment environment or any other relevant information, to help reproduce the issue.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则