擅长:python、mysql、java
<p>我还执行了以下操作以获取在非容器阶段的cloudformation中配置的环境变量,例如常规命令</p>
<pre><code>/opt/elasticbeanstalk/bin/get-config environment | python -c "import json,sys; obj=json.load(sys.stdin); f = open('/tmp/eb_env', 'w'); f.write('\n'.join(map(lambda x: 'export ' + x[0] + '=' + x[1], obj.iteritems())))"
</code></pre>
<p>执行此命令后,您将在/tmp/ebúenv中有一个包含所有环境变量的文件。只需在需要环境变量的命令之前执行以下命令</p>
<pre><code>source /tmp/eb_env
</code></pre>
<p>示例</p>
<pre><code>source /tmp/eb_env && echo $MY_CUSTOM_ENV
</code></pre>
<p>在elastic beanstalk的配置文件中,如下所示:</p>
<pre><code>commands:
02-make-sure-we-can-get-our-env-in-the-instance-itself:
command: "/opt/elasticbeanstalk/bin/get-config environment | python -c 'import json,sys; obj=json.load(sys.stdin); f = open(\'/tmp/eb_env\', \'w\'); f.write(\'\n\'.join(map(lambda x: \'export \' + x[0] + \'=\' + x[1], obj.iteritems())))'"
</code></pre>