1
votes

I'm working with Django v1.11.2 setup using Django Storages to host files on S3. I've got the storages configured correctly as far as I can tell. I can successfully deploy and run 'collectstatic' without a problem. The files show up in S3 and the site works as expected.

I'm also using the Django Import / Export module and have it set to store files using the MediaStorage option. After I run an import it successfully creates a 'media' folder in my S3 bucket alongside my 'static' bucket.

Here's where the problem arises. If I now run an eb deploy and push updates of any kind I receive this error.

[Instance: i-037825ca3bdf4a5c5] Command failed on instance. Return code: 1 Output: (TRUNCATED)...(path) File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/files/storage.py", line 111, in path raise NotImplementedError("This backend doesn't support absolute paths.") NotImplementedError: This backend doesn't support absolute paths. container_command 03_collectstatic in .ebextensions/02_python.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

Ok. Hmmm. That's odd. So now if I go into my S3 bucket. Delete ONLY the 'media' folder and do deploy the application again the error is resolved.

Here are the values I have within my settings.py file.

AWS_STORAGE_BUCKET_NAME = 'my-s3-bucket'
AWS_S3_REGION_NAME = 'us-east-1'
AWS_ACCESS_KEY_ID = 'xxxxxxxxxxxxx'
AWS_SECRET_ACCESS_KEY = 'xxxxxxxxxxxxxxxxxxx'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME

STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'

MEDIAFILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

# custom_storages.py
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage

class StaticStorage(S3Boto3Storage):
    location = settings.STATICFILES_LOCATION

class MediaStorage(S3Boto3Storage):
  location = settings.MEDIAFILES_LOCATION

This is the log straight out of EB

[2017-09-21T02:41:17.534Z] INFO  [15715] - [Application xxxxxxxxxxxx.8a53f090a2c.20170921-024002@37/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_xxxxxxxx/Command 03_collectstatic] : Activity execution failed, because: base dir path /opt/python/bundle/4/app
  Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
  execute_from_command_line(sys.argv)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
  utility.execute()
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
  self.execute(*args, **cmd_options)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
  output = self.handle(*args, **options)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
  collected = self.collect()
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
  handler(path, prefixed_path, storage)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 357, in copy_file
  source_path = source_storage.path(path)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/files/storage.py", line 111, in path
  raise NotImplementedError("This backend doesn't support absolute paths.")
  NotImplementedError: This backend doesn't support absolute paths.
   (ElasticBeanstalk::ExternalInvocationError)

I've been beating my head against the wall on this one all day. Any and all suggestions are appreciated. Thank you.

1

1 Answers

1
votes

Well I finally figured this out thanks to this post. It all was because of my STATICFILES_FINDERS setting I changed it from.

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

To

STATICFILES_FINDERS = (
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
        'django.contrib.staticfiles.finders.FileSystemFinder',
    )

Which makes total sense because it was checking in the media folder for my static files. I inherited this project so didn't even realize they had this setup that way.