Torchserve Managment API not working with s3 presigned URI


I am trying to use the management API with a S3 presigned URL to download and register a new model. This is the code snippet:

   def create_presigned_url(self, bucket_name, object_name, expiration=3600):
        """Generate a presigned URL to share an S3 object

        :param bucket_name: string
        :param object_name: string
        :param expiration: Time in seconds for the presigned URL to remain valid
        :return: Presigned URL as string. If error, returns None.

        # Generate a presigned URL for the S3 object
        s3_client = boto3.client('s3')
            response = s3_client.generate_presigned_url('get_object',
                                                        Params={'Bucket': bucket_name,
                                                                'Key': object_name},
        except ClientError as e:
            return None

        # The response contains the presigned URL
        return response
presigned_uri = self.create_presigned_url(bucket_name, object_name)
response ="{}".format(presigned_uri))

Doing a normal GET on the presigned URI works but it doesn’t work when used with the model management API. I tried all the workarounds mentioned in #669 but those are not giving any results as well. Can you please recommend what to do to make it work. Listing the errors I get in various situations:

Using the raw presigned URI:

  "code": 400,
  "type": "DownloadArchiveException",
  "message": "Failed to download archive from:****"

Replacing & with %26:

  "code": 400,
  "type": "DownloadArchiveException",
  "message": "Failed to download archive from:****&Signature=****=&x-amz-security-token=****&Expires=1635283752"

Using the torchserve 0.4.2-cpu docker image.

Your Environment

  • Installed using source? [yes/no]: no
  • Are you planning to deploy it using docker container? [yes/no]: yes
  • Is it a CPU or GPU environment?: CPU
  • Using a default/custom handler? [If possible upload/share custom handler/model]: custom but unrelated to the issue.
  • What kind of model is it e.g. vision, text, audio?: text
  • Are you planning to use local models from model-store or public url being used e.g. from S3 bucket etc.?
    [If public url then provide link.]: S3 bucket

Expected Behavior

It should be able to download the model from S3 and register it.

Current Behavior

Returning a 400

Steps to Reproduce

  1. Just upload a mar file to a s3 bucket
  2. Create the presigned uri using the given code and then call the managment API to try to register the model.

Reference Issue on torchserve: