1

I want to use MinIO Object Transforms, but I got an error when trying to download a presigned URL. I followed their documentation exactly, as shown in this link.

I also watched this video and rechecked everything. What should I do?

I got this error:

<?xml version="1.0" encoding="UTF-8"?>\n
<Error>
    <Code>InvalidTokenId</Code>
    <Message>The security token included in the request is invalid</Message>
    <Key>000bd20a46790a88ff79cc3d4f5d21e0d6e121b6dc9fe10c76271f379af5fb2f.webp</Key>
    <BucketName>place</BucketName>
    <Resource>/place/000bd20a46790a88ff79cc3d4f5d21e0d6e121b6dc9fe10c76271f379af5fb2f.webp</Resource>
    <RequestId>183298B2B91FD9C9</RequestId>
    <HostId>dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8</HostId>
</Error>

here is client code:

minio_endpoint = '127.0.0.1:90'
minio_access_key = 'access'
minio_secret_key = 'secret'

# Initialize a Minio client
s3Client = Minio(minio_endpoint, access_key=minio_access_key, secret_key=minio_secret_key, secure=False)

# Set lambda function target via `lambdaArn`
lambda_arn = 'arn:minio:s3-object-lambda::resize-image:webhook'

# Generate presigned GET URL with lambda function
bucket_name = 'place'
object_name = '000bd20a46790a88ff79cc3d4f5d21e0d6e121b6dc9fe10c76271f379af5fb2f.webp'
expiration = timedelta(seconds=1000)  # Expiration time in seconds

req_params = {'lambdaArn': lambda_arn , "width": "10"}
presigned_url = s3Client.presigned_get_object(bucket_name, object_name, expires=expiration, extra_query_params= req_params )
print(presigned_url)

# Use the presigned URL to retrieve the data using requests
response = requests.get(presigned_url)

if response.status_code == 200:
    content = response.content
    print("Transformed data:\n")
else:
    print("Failed to download the data. Status code:", response.status_code, "Reason:", response.reason)
    print("\n",response.content)

here is my lambda handler function

package main

import (
    "context"
    "fmt"
    "log"
    "net/url"
    "time"

    "github.com/minio/minio-go/v7"
    "github.com/minio/minio-go/v7/pkg/credentials"
)

func main() {

   // Connect to the MinIO deployment
   s3Client, err := minio.New("localhost:90", &minio.Options{
      Creds:  credentials.NewStaticV4("access", "secret", ""),
      Secure: false,
   })
   if err != nil {
      log.Fatalln(err)
   }

   // Set the Lambda function target using its ARN
   reqParams := make(url.Values)
   reqParams.Set("lambdaArn", "arn:minio:s3-object-lambda::resize-image:webhook")

   // Generate a presigned url to access the original object
   presignedURL, err := s3Client.PresignedGetObject(context.Background(), "place", "testobject", time.Duration(1000)*time.Second, reqParams)
   if err != nil {
      log.Fatalln(err)
   }

   // Print the URL to stdout
   fmt.Println(presignedURL)
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.