简体   繁体   English

gunicorn - django - boto - 通过S3保存静态文件 - 如何将AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY设置为环境变量

[英]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. 我使用s3来编写我的静态文件和django-storage来为它们提供服务。

    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: 我尝试在heroku上部署我的应用程序,为了验证我的进程访问S3,可以设置访问凭据:

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

This worked on heroku. 这适用于heroku。

I tried the same approach for webfaction, but always get the following error: 我为webfaction尝试了相同的方法,但总是得到以下错误:

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. 我可以通过gunicorn访问S3上的文件的变量。

Please note that I only want to pass the gunicorn process the credentials. 请注意,我只想通过gunicorn进程凭据。 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. 我对webfaction一无所知,但boto也会在boto配置文件中查找凭据。 By default it will look in /etc/boto.cfg and in ~/.boto . 默认情况下,它将在/etc/boto.cfg~/.boto This file is an INI style config file and you need to add your credentials like this: 此文件是INI样式的配置文件,您需要添加如下所示的凭据:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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