How to set an environment variable in Amazon Elastic Beanstalk (Python)(如何在 Amazon Elastic Beanstalk (Python) 中设置环境变量)
问题描述
我最近一直在开发一个 Django 应用程序,试图让它与 Amazon Elastic Beanstalk 一起工作.
I have been working on a Django application lately, trying to get it to work with Amazon Elastic Beanstalk.
在我的 .ebextensions/python.config 文件中,我设置了以下内容:
In my .ebextensions/python.config file, I have set the following:
option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: ProductionBucket
value: s3-bucket-name
- namespace: aws:elasticbeanstalk:application:environment
option_name: ProductionCache
value: memcached-server.site.com:11211
但是,每当我查看服务器时,都没有设置此类环境变量(因此,当我尝试 os.getenv('ProductionBucket')
However, whenever I look on the server, no such environment variables are set (and as such, aren't accessible when I try os.getenv('ProductionBucket')
我遇到了这个 this page,它似乎试图记录所有命名空间.我也尝试使用 PARAM1 作为选项名称,但结果相似.
I came across this this page which appears to attempt to document all the namespaces. I've also tried using PARAM1 as the option name, but have had similar results.
如何在 Amazon Elastic Beanstalk 中设置环境变量?
How can I set environment variables in Amazon Elastic Beanstalk?
编辑:
我还尝试在所有其他仅导出环境变量的命令之前添加一个命令:
EDIT:
I have also tried adding a command prior to all other commands which would just export an environment variable:
commands:
01_env_vars:
command: "source scripts/env_vars"
...这也失败了
推荐答案
我检查了使用现代(即非遗留)容器,并在/opt/elasticbeanstalk/deploy/configuration/containerconfiguration 下找到它作为 json 文件.
I've checked using a modern (i.e., non legacy) container, and found it under /opt/elasticbeanstalk/deploy/configuration/containerconfiguration as a json file.
行为似乎是平台相关的:我记得特别是在 PHP 中,它还创建了一些带有值的 shell 脚本.
The Behaviour seems to be Platform-Dependent: I remember in PHP in particular, it also creates some shell scripts with the values.
无论如何,请查看/opt/elasticbeanstalk/hooks/configdeploy.
Regardless of that, look into /opt/elasticbeanstalk/hooks/configdeploy.
Java 案例,它运行这个 python 脚本,对你来说看起来很方便:
Java case again, it runs this python script, which looks quite handy for you:
https://gist.github.com/19c1e4b718f9a70a4ce1
这篇关于如何在 Amazon Elastic Beanstalk (Python) 中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Amazon Elastic Beanstalk (Python) 中设置环境变量
基础教程推荐
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 包装空间模型 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
