djangoamazon-s3boto3django-storagepython-django-storages

Django Storage and Boto3 not retrieving Media from AWS S3


I am using a development server to test uploading and retrieving static files from AWS S3 using Django storages and Boto3. The file upload worked but I cannot retrieve the files.

This is what I get:

enter image description here

And when I check out the URL in another tab I get this

**This XML file does not appear to have any style information associated with it. The document tree is shown below.**
<Error>
<Code>IllegalLocationConstraintException</Code>
    <Message>The me-south-1 location constraint is incompatible for the region specific endpoint this request was sent to.</Message>
    <RequestId></RequestId>
    <HostId></HostId>
</Error>

Also I configured the settings.py with my own credentials and IAM user

AWS_ACCESS_KEY_ID = <key>
AWS_SECRET_ACCESS_KEY = <secret-key>
AWS_STORAGE_BUCKET_NAME = <bucket-name>
AWS_DEFAULT_ACL = None
AWS_S3_FILE_OVERWRITE = False
AWS_S3_REGION_NAME = 'me-south-1'
AWS_S3_USE_SSL = True
AWS_S3_VERIFY = False
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Solution

  • Please check in your AWS Identity & Access Management Console (IAM) whether your access keys have proper S3 permissions assigned to them.

    Also, make sure you have installed AWS CLI and setup your credentials in your machine.

    You can try running the below command and verify it.

    $ aws s3 ls
    2018-12-11 17:08:50 my-bucket
    2018-12-14 14:55:44 my-bucket2
    

    Reference : https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html