Heroku Environment Variables for S3 Bucket Not Being Read in Container Instance of Django App

Viewed 137

I am pushing my Django app to Heroku as a container instance, but I am getting problems where it doesn't appear to be reading the environment variables. They are set using "heroku config:set AWS_STORAGE_BUCKET_NAME='my_bucket'" and so on.

My python code working in development and uses the bucket storage successfully, but when pushing to Heroku I get the error shown which implies it is not passing the value for the bucket name.

remote:            if not VALID_BUCKET.search(bucket) and not VALID_S3_ARN.search(bucket):
remote:        TypeError: expected string or bytes-like object

My settings file looks like this:

AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_S3_REGION_NAME = os.environ.get('AWS_S3_REGION_NAME')
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')

AWS_S3_CUSTOM_DOMAIN = '{}.s3.amazonaws.com'.format(AWS_STORAGE_BUCKET_NAME)

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

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

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

I have a .yml file and I am thinking that I might need some configuration in there, but can someone help advise what that should be? It looks as below and I have tried adding environment variables under the config section to see if it makes a difference, but it didn't.

setup:
  addons:
    - plan: 'heroku-postgresql:hobby-dev'
      as: DATABASE
  config:
    BUILD_WITH_GEO_LIBRARIES: '1'
    DISABLE_COLLECTSTATIC: '1'
build:
  packages:
    - gdal-bin
  languages:
    - python
run:
  web: gunicorn booksapp.wsgi --log-file -
0 Answers
Related