如何在 Amazon Elastic Beanstalk (Python) 中设置环境变量 [英] How to set an environment variable in Amazon Elastic Beanstalk (Python)

查看:59
本文介绍了如何在 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) 中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆