Skip to content

Transforms with Object Lambda The security token included in the request is invalid #1491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mmahditalachi opened this issue Apr 3, 2025 · 4 comments

Comments

@mmahditalachi
Copy link

mmahditalachi commented Apr 3, 2025

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 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'

s3Client = Minio(minio_endpoint, access_key=minio_access_key, secret_key=minio_secret_key, secure=False)

lambda_arn = 'arn:minio:s3-object-lambda::resize-image:webhook'

bucket_name = 'place'
object_name = '000bd20a46790a88ff79cc3d4f5d21e0d6e121b6dc9fe10c76271f379af5fb2f.txt'
expiration = timedelta(seconds=1000)  

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)

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 lambda handler:

from flask import Flask, request, abort, make_response
import requests

app = Flask(__name__)
@app.route('/', methods=['POST'])
def get_webhook():
   if request.method == 'POST':
      event = request.json

      object_context = event["getObjectContext"]

      s3_url = object_context["inputS3Url"]

      request_route = object_context["outputRoute"]
      request_token = object_context["outputToken"]

      r = requests.get(s3_url)
      original_object = r.content.decode('utf-8')

      transformed_object = original_object.swapcase()

      resp = make_response(transformed_object, 200)
      resp.headers['x-amz-request-route'] = request_route
      resp.headers['x-amz-request-token'] = request_token
      return resp

   else:
      abort(400)

if __name__ == '__main__':
   app.run()
@balamurugana
Copy link
Member

The error says InvalidTokenId. As the error is from server, please check at server side and make sure valid token is passed.

@mmahditalachi
Copy link
Author

Where should I check? Should I check from the console or the MinIO client?

@balamurugana
Copy link
Member

Please open an issue in minio server

@mmahditalachi
Copy link
Author

mmahditalachi commented Apr 3, 2025

It's done, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants