'Digitalocean space access denied

I created a digital ocean storage space. The url of the space is as https://storagespace.nyc3.digitaloceanspaces.com However, when I click on the url to open on the browser I get the following error:

<Error>
<Code>AccessDenied</Code>
<BucketName>storagespace</BucketName>
<RequestId>tx000000000000001618a5e-0081246af3-1805687a-nyc3c</RequestId>
<HostId>1805987a-nyc3c-nyc3-zg03</HostId>
</Error>

I have no idea what this error means or why I'm having it. I connected the s3 bucket with my django website and the static files are not being served to the browser as well, instead I get 403 forbidden error. Please how do I remove this access denied error?



Solution 1:[1]

tl;dr follow their official tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-scalable-django-app-with-digitalocean-managed-databases-and-spaces

Unfortunately, we don't really know what packages you're using (like are you using Django-storages to to get those static files to S3?). I have no experience with digital ocean, but here are some things to try:

As you can see in the tutorial, they have these settings which I presume digital ocean has provided you:

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

# Moving static assets to DigitalOcean Spaces as per:
# https://www.digitalocean.com/community/tutorials/how-to-set-up-object-storage-with-django
AWS_ACCESS_KEY_ID = 'your_spaces_access_key'
AWS_SECRET_ACCESS_KEY = 'your_spaces_secret_key'

AWS_STORAGE_BUCKET_NAME = 'your_space_name'
AWS_S3_ENDPOINT_URL = 'spaces_endpoint_URL'
AWS_S3_CUSTOM_DOMAIN = 'spaces_edge_endpoint_URL'
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}
AWS_LOCATION = 'static'
AWS_DEFAULT_ACL = 'public-read'

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

STATIC_URL = '{}/{}/'.format(AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATIC_ROOT = 'static/'

Solution 2:[2]

The problem is that you were missing AWS_DEFAULT_ACL = 'public-read' in your settings.py at the time you ran python manage.py collectstatic. Now, you need to go back and set the permission on all the files throwing 403 Forbidden error manually to public-read. I'd suggest to also add AWS_DEFAULT_ACL = 'public-read' to your settings for future collectstatic commands.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 acw
Solution 2 EarlyCoder