0

I'm trying to integrate S3 Bucket with my django application. But always getting this error.

raise ValueError("Invalid endpoint: %s" % endpoint_url)
ValueError: Invalid endpoint: <bucket_name>.s3.amazonaws.com

These are my settings.py configurations

    AWS_ACCESS_KEY_ID = config('STATIC_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY = config('STATIC_SECRET_KEY')
    AWS_S3_REGION_NAME = config('AWS_REGION')
    AWS_STORAGE_BUCKET_NAME = config('STATIC_BUCKET_NAME')
    AWS_S3_ENDPOINT_URL =  '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
    AWS_S3_OBJECT_PARAMETERS = {
        'CacheControl': 'max-age=86400',
    }

AWS_LOCATION = 'static'
AWS_DEFAULT_ACL = 'public-read'

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATIC_URL =  'https://%s/%s/' % (AWS_S3_ENDPOINT_URL, AWS_LOCATION)

I have referred the answers here, ValueError: Invalid endpoint: https://s3..amazonaws.com

Region is set correct.

Rohit Hazare
  • 1
  • 1
  • 4

1 Answers1

0

The problem was because you didn't allow your s3 bucket to be accessible. Please learn How to add Bucket policy and permissions for public access.

And in your settings.py file. I added my Configurations like this:

AWS_ACCESS_KEY_ID = 'Your Access Key Id'
AWS_SECRET_ACCESS_KEY = 'Your Secret Key id'
""""""""""
""""""""""
""""""""""
  • I tried as suggested in the links. Created a folder and tried to access from browser. Works perfect. But when I try to do collectstatic with Django getting the same error. – Rohit Hazare Jun 13 '22 at 05:54
  • Did you try to upload image or anything from your website ? Please try and told me what error is given to you. –  Jun 13 '22 at 06:02
  • Changed the AWS_S3_ENDPOINT_URL variable to AWS_S3_CUSTOM_URL. AWS S3 was expecting some other value for AWS_S3_ENDPOINT_URL and my declaration was overwriting that. Facing a new error now when the pages are loading. SuspiciousOperation at /models/login/ Attempted access to '/assets/img/favicon.ico' denied. – Rohit Hazare Jun 13 '22 at 11:06
  • Django is adding some parameters to the static urls. https://bucket_name.s3.amazonaws.com/static/admin/css/nav_sidebar.css?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ACCESS-KEY%2F20220613%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20220613T110930Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=SIGNATURE – Rohit Hazare Jun 13 '22 at 11:12