Wdrożenie kończy się niepowodzeniem z następującym błędem

  Traceback (most recent call last):
  File "/opt/python/ondeck/app/manage.py", line 21, in <module>
  main()
  File "/opt/python/ondeck/app/manage.py", line 17, in main
  execute_from_command_line(sys.argv)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
  utility.execute()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
  self.execute(*args, **cmd_options)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
  output = self.handle(*args, **options)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
  collected = self.collect()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
  handler(path, prefixed_path, storage)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 342, in copy_file
  if not self.delete_file(path, prefixed_path, source_storage):
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 249, in delete_file
  if self.storage.exists(prefixed_path):
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 524, in exists
  self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/client.py", line 272, in _api_call
  return self._make_api_call(operation_name, kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/client.py", line 549, in _make_api_call
  api_params, operation_model, context=request_context)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/client.py", line 595, in _convert_to_request_dict
  api_params, operation_model, context)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/client.py", line 627, in _emit_api_params
  params=api_params, model=operation_model, context=context)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/hooks.py", line 356, in emit
  return self._emitter.emit(aliased_event_name, **kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/hooks.py", line 228, in emit
  return self._emit(event_name, kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/hooks.py", line 211, in _emit
  response = handler(**kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/handlers.py", line 223, in validate_bucket_name
  if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket):
  TypeError: expected string or bytes-like object
   (ElasticBeanstalk::ExternalInvocationError)

Śledzenie błędów nie pomaga mi zrozumieć, na czym dokładnie polega problem

Settings.py

AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME']
AWS_S3_REGION_NAME = os.environ['AWS_S3_REGION_NAME']  # e.g. us-east-2
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']

# Tell django-storages the domain to use to refer to static files.
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME

# Tell the staticfiles app to use S3Boto3 storage when writing the collected static files (when
# you run `collectstatic`).
# STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

DEFAULT_FILE_STORAGE = custom_storages.MediaStorage
STATICFILES_STORAGE = custom_storages.StaticStorage

STATICFILES_LOCATION = os.environ['STATICFILES_LOCATION']
MEDIAFILES_LOCATION = os.environ['MEDIAFILES_LOCATION']

STATIC_DIRECTORY = '/static/'
STATIC_URL = AWS_S3_CUSTOM_DOMAIN + STATIC_DIRECTORY

MEDIA_DIRECTORY = '/media/'
MEDIA_URL = AWS_S3_CUSTOM_DOMAIN + MEDIA_DIRECTORY

Custom_storages.py

from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage


class StaticStorage(S3Boto3Storage):
    location = settings.STATICFILES_LOCATION
    default_acl = 'public-read'

class MediaStorage(S3Boto3Storage):
    location = settings.MEDIAFILES_LOCATION
    default_acl = 'private'
    file_overwrite = False

Próbowałem zmienić kolejność MEDIA_ROOT i STATIC_ROOT, co nie pomogło.

Obecny kod działa doskonale na moim laptopie, który jest komputerem Mac.

Każda pomoc w rozwiązaniu tego problemu jest bardzo ceniona. Dziękuję Ci!

0
aravind marthineni 19 grudzień 2019, 20:54

1 odpowiedź

Rozwiązałem ten problem, dodając AWS_DEFAULT_ACL = None do settings.py

Byłem zdania, że ustawienie default_acl w custom_storages.py wystarczy, ale najwyraźniej samo to nie wystarczy. samo dodanie tego do settings.py i ponowne wdrożenie działało jak magia.

0
aravind marthineni 19 grudzień 2019, 23:06