Skip to content
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

An error occurred (InvalidArgument) when calling the PutObject operation: X-Amz-Security-Token #1453

Open
HamedOsama opened this issue Sep 23, 2024 · 0 comments

Comments

@HamedOsama
Copy link

I am using R2 as my cloud storage and deploy to Vercel as serverless functions using Django and DRF

Python version: 3.8.0

boto3==1.35.20
Django==4.2.14
django-storages==1.14.4
djangorestframework==3.15.2
urllib3==1.26.20

Settings I am using:

bucket_name = config("CLOUDFLARE_R2_BUCKET")
endpoint_url = config("CLOUDFLARE_R2_BUCKET_ENDPOINT")
access_key = config("CLOUDFLARE_R2_ACCESS_KEY")
secret_key = config("CLOUDFLARE_R2_SECRET_KEY")
signature_version = config("CLOUDFLARE_R2_SIGNATURE_VERSION")

STORAGES = {
    "default": {
        "BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
        "OPTIONS": {
            "bucket_name": bucket_name,
            "endpoint_url": endpoint_url,
            "access_key": access_key,
            "secret_key": secret_key,
            "signature_version": signature_version,
            "default_acl": "public-read",
        },
    },
    # keep static files in local
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    }
}

I tried these settings, and it also didn't work.

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = config("CLOUDFLARE_R2_ACCESS_KEY")
AWS_SECRET_ACCESS_KEY = config("CLOUDFLARE_R2_SECRET_KEY")
AWS_STORAGE_BUCKET_NAME = config("CLOUDFLARE_R2_BUCKET")
AWS_S3_ENDPOINT_URL = config("CLOUDFLARE_R2_BUCKET_ENDPOINT")

vercel.json config

{
    "builds": [{
        "src": "core/wsgi.py",
        "use": "@vercel/python",
        "config": { "maxLambdaSize": "15mb", "runtime": "python3.8" }
    },
    {
        "src": "build_files.sh",
        "use": "@vercel/static-build",
        "config": { "distDir": "staticfiles_build" }
    }],
    "routes": [
        {
            "src": "/static/(.*)",
            "dest": "/static/$1"
        },
        {
            "src": "/(.*)",
            "dest": "core/wsgi.py"
        }
    ]
}

I got this error on uploading any object

image
image
image

Also this on getting any object
image

It works fine locally, but I got this error once I deployed it.

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

1 participant