简体   繁体   中英

gunicorn - django - boto -serve static files via S3 - how to set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables

I m using s3 to story my static files and django-storages to serve them.

    STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
    AWS_STORAGE_BUCKET_NAME = 'mybucket'
    STATIC_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME

I tried to deploy my app on heroku and in order to authenticate my process to access S3 one can set the access credentials as such:

export AWS_ACCESS_KEY_ID=<key ID>
export AWS_SECRET_ACCESS_KEY=<key>

This worked on heroku.

I tried the same approach for webfaction, but always get the following error:

NoAuthHandlerFound at /admin/
No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials

So my question is: how do I properly setup the credentials as env. variables that I can access the files on S3 via gunicorn.

Please note that I only want to pass the gunicorn process the credentials. I do not want to store them in a config. file.

I don't really know anything about webfaction, but boto will also look for credentials in a boto config file. By default it will look in /etc/boto.cfg and in ~/.boto . This file is an INI style config file and you need to add your credentials like this:

[Credentials]
aws_access_key_id = <key ID>
aws_secret_access_key = <key>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM