python - python boto无法获取docker容器的环境变量
问题描述
我使用安装了 golang 的
dockerjrei/systemd-ubuntu:18.04
映像并设置并github.com/remind101/assume-role
运行Django
uwsgi
nginx
他 Python 版本是3.7,boto版本是2.49.0
此外,Django 要求安装在venv中。
在 ~/.aws/config 中设置 aws 配置文件并在 ~/.aws/credentials 中设置凭据后
服务器工作正常,但boto包无法获取environ变量
Django 页面显示错误消息:
NoAuthHandlerFound at /
No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials
Request Method: GET
Request URL: http://localhost/
Django Version: 3.0.5
Exception Type: NoAuthHandlerFound
Exception Value:
No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials
Exception Location: /opt/web/camelot-portal-env/lib/python3.7/site-packages/boto/auth.py in get_auth_handler, line 1021
Python Executable: /opt/web/camelot-portal-env/bin/uwsgi
Python Version: 3.7.8
Python Path:
['.',
'',
'/usr/lib/python37.zip',
'/usr/lib/python3.7',
'/usr/lib/python3.7/lib-dynload',
'/opt/web/camelot-portal-env/lib/python3.7/site-packages']
我检查了$AWS_ACCESS_KEY_ID
和$AWS_SECRET_ACCESS_KEY
都不是空的,我尝试配置$AWS_CREDENTIAL_FILE
两次,到~/.aws/config and
~/.aws/credentials
两次我重新启动 uwsgi 服务,boto 仍然没有得到任何密钥或密钥 ID。
最后,如果我安装需求并python manage.py runserver
在本地环境中使用,
boto包可以正常获取环境变量,一切正常。
哪一部分是问题?码头集装箱?uwsgi? 还是venv?任何想法?
解决方案
8/15 编辑
我发现问题出在 uWSGI 上,它没有获取 linux env 变量。除非我在这样的文件中设置 env:envfile
VAR1=VALUE1
VAR2=VALUE2
和 uwsgi 文件:
for-readline = /path/to/envfile
env = %(_)
endfor =
那么uwsgi的python就可以通过os.environ
.
但是,我仍然无法通过 aws 令牌验证,我认为这是另一个问题。
推荐阅读
- c - 为什么在任意内存位置设置值不起作用?
- django - 无法将方法作为 POST 从 django 模板传递到 django 视图
- r - 有没有办法改变在ggplot的计算字段上显示为条形图数据标签的有效数字的数量?
- java - 如何仅打印最大键值?
- android - Android - TextureView + SurfaceHolder.Callback
- javascript - 如何在 SQL 中替换 json 字符串中的数字数组?
- java - 如何配置测试套件始终将常量注入到所有类实例的@value私有字段中
- c# - 将文件上传到 WindowsForms C# 中的 Rest API
- java - 带有实体列表的 Android Room IN 条件
- java - 另一个使用 Spring 的 JUNIT 测试——Autowired not working 问题