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) 中设置环境变量


基础教程推荐
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01