My app ID is 18446. Can someone help me add S3 to the app?
CC @luke.smith
Hi @ankit, thanks for writing in! Iâll be happy to configure this for you; stand by for confirmation.
Hi @luke.smith!
For SendGrid weâre not providing it as an add-on anymore. Please ask the client if they have an account with any e-mail service already, e.g. SendGrid, MailChimp, Mailgun, SendInBlue, etc. and use that if they do. If they donât already have an account, ask your PM to set it up for them using their provided e-mail address.
Please stand by for S3 confirmation.
The following variables have been added to your appâs production environment:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_STORAGE_BUCKET_NAME
AWS_STORAGE_REGION
They are hidden from your CB Dashboard but available to the app.
Please let me know if there is anything else I can help you with. Happy coding!
Thanks a lot, Dmitrii
You are always welcome!
Hi Dmitrii, any ideas on how I can access these environment variables as I need to test file upload to s3 bucket in development setting?
Also, as for gaining access to the s3 account is this possible in order to check file uploads are functioning correctly? Thanks
@luke.smith, S3 is provided only for production and staging environment. We encourage use of standard file storage in local development. Our django template is tested to work with these variables and comes with S3Boto included, so there shouldnât be any errors.
If you need to check anything you can always post to support.
Hi @dmitrii.k ,
Just tried to deploy the application and Iâm getting a key error for the AWS production environment variables, are they definitely set, or am I doing something wrong?
Error & traceback:
Step 9/12 : RUN python3 manage.py collectstatic --no-input
â> Running in 0efe59ca628f
e[91mTraceback (most recent call last):
File â/usr/local/lib/python3.6/dist-packages/environ/environ.pyâ, line 273, in get_value
value = self.ENVIRON[var]
File â/usr/lib/python3.6/os.pyâ, line 669, in getitem
raise KeyError(key) from None
KeyError: âAWS_ACCESS_KEY_IDâ
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File âmanage.pyâ, line 21, in
main()
File âmanage.pyâ, line 17, in main
execute_from_command_line(sys.argv)
File â/usr/local/lib/python3.6/dist-packages/django/core/management/init.pyâ, line 381, in execute_from_command_line
utility.execute()
File â/usr/local/lib/python3.6/dist-packages/django/core/management/init.pyâ, line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File â/usr/local/lib/python3.6/dist-packages/django/core/management/init.pyâ, line 211, in fetch_command
settings.INSTALLED_APPS
File â/usr/local/lib/python3.6/dist-packages/django/conf/init.pyâ, line 79, in getattr
self._setup(name)
File â/usr/local/lib/python3.6/dist-packages/django/conf/init.pyâ, line 66, in _setup
self._wrapped = Settings(settings_module)
File â/usr/local/lib/python3.6/dist-packages/django/conf/init.pyâ, line 157, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File â/usr/lib/python3.6/importlib/init.pyâ, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File ââ, line 994, in _gcd_import
File ââ, line 971, in _find_and_load
File ââ, line 955, in _find_and_load_unlocked
File ââ, line 665, in _load_unlocked
File ââ, line 678, in exec_module
File ââ, line 219, in _call_with_frames_removed
File â/opt/webapp/ex_curator_18446/settings.pyâ, line 63, in
AWS_ACCESS_KEY_ID = env.str(âAWS_ACCESS_KEY_IDâ)
File â/usr/local/lib/python3.6/dist-packages/environ/environ.pyâ, line 134, in str
value = self.get_value(var, default=default)
File â/usr/local/lib/python3.6/dist-packages/environ/environ.pyâ, line 277, in get_value
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the AWS_ACCESS_KEY_ID environment variable
e[0mThe command â/bin/sh -c python3 manage.py collectstatic --no-inputâ returned a non-zero code: 1
And the relevant part of settings.py:
AWS_ACCESS_KEY_ID = env.str(âAWS_ACCESS_KEY_IDâ)
AWS_SECRET_ACCESS_KEY = env.str(âAWS_SECRET_ACCESS_KEYâ)
AWS_STORAGE_BUCKET_NAME = env.str(âAWS_STORAGE_BUCKET_NAMEâ)
AWS_S3_REGION_NAME = env.str(âAWS_STORAGE_REGIONâ)
Hi @luke.smith,
S3 is meant to be used for uploaded media, static files should still use the standard file backend. AWS vars are not available during build, so once you re-configure static files to use the file storage itâll deploy.
Hi Dmitrii, thanks again for the response.
I am already using file storage for static files and have not modified the settings.py from the scaffold:
Static files (CSS, JavaScript, Images)
Managing static files (e.g. images, JavaScript, CSS) | Django documentation | Django
STATIC_URL = â/static/â
MIDDLEWARE += [âwhitenoise.middleware.WhiteNoiseMiddlewareâ]
AUTHENTICATION_BACKENDS = (
âdjango.contrib.auth.backends.ModelBackendâ,
âallauth.account.auth_backends.AuthenticationBackendâ
)
STATIC_ROOT = os.path.join(BASE_DIR, âstaticfilesâ)
STATICFILES_DIRS = [
os.path.join(BASE_DIR, âstaticâ)
]
STATICFILES_STORAGE = âwhitenoise.storage.CompressedManifestStaticFilesStorageâ
STATICFILES_FINDERS = (
âdjango.contrib.staticfiles.finders.FileSystemFinderâ,
âdjango.contrib.staticfiles.finders.AppDirectoriesFinderâ,
)
And for uploaded media I have defined another media root:
MEDIA_ROOT = os.path.join(BASE_DIR, âmediaâ)
MEDIA_URL = â/media/â
Which, in development I define as a url in urls.py:
if settings.DEBUG:
urlpatterns += [
url(râ^media/(?P.*)$', serve, {
âdocument_rootâ: settings.MEDIA_ROOT,
}),
]
Iâm thinking this may be an issue with the scaffold not having the s3 support dependencies installed as looking in the pipfile, s3boto isnât included:
[[source]]
verify_ssl = true
url = âSimple indexâ
name = âpypiâ
[dev-packages]
[requires]
python_version = â3.7â
[packages]
django = â~=2.2.3â
django-environ = â~=0.4.5â
psycopg2 = â~=2.8.5â
waitress = â~=1.4.3â
whitenoise = â~=5.1.0â
djangorestframework = â~=3.11.0â
django-bootstrap4 = â~=1.1.1â
django-allauth = â~=0.41.0â
django-rest-auth = â~=0.9.5â
django-extensions = â~=2.2.9â
packaging = â*â
drf-yasg = â~=1.17.1â
fcm-django = â~=0.3.4â
pyyaml = â~=5.3.1â
Update: I changed from env.str() to os.environ.get() and the build succeeds, but files are hosted locally on the server and not served from s3
Hi @luke.smith,
Adding S3 Boto is definitely going to be helpful. However, I caught the real reason for the failed build:
Youâre not providing the default value, and since this var is absent inside the build environment itâs raising an error. Apologies for not catching it initiially.
Hi,
I changed from env.str to os.environ.get() and build succeeded, should I still be using env.str with a default value instead?
Also, is there a link to an updated django scaffold pipfile? Seeing as this appâs missing s3boto it is also likely that it is also missing other s3 dependencies
Hi @dmitrii.k,
I changed from env.str to os.environ.get() and build succeeded, should I still be using env.str with a default value instead?
Also, is there a link to an updated django scaffold pipfile? Seeing as this appâs missing s3boto it is also likely that it is also missing other s3 dependencies