弹性魔豆连接到RDS从外壳SSH连接到、外壳、弹性、魔豆

2023-09-11 09:03:55 作者:╰胭脂俗粉゛

我有一个弹性魔豆EC2实例连接到一个PostgreSQL的RDS Python应用程序。

I have a python application on an Elastic Beanstalk EC2 instance which is connected to an PostgreSQL RDS.

我的应用程序工作正常,并使用由弹性魔豆设置环境变量来连接数据库:

My application works fine and uses the environment variables that are set by Elastic Beanstalk to connect with the database:

os.environ['RDS_DB_NAME']
os.environ['RDS_USERNAME']
os.environ['RDS_PASSWORD']
os.environ['RDS_HOSTNAME']
os.environ['RDS_PORT']

不过,这并没有当我登录与SSH EC2实例工作。 RDS的环境变量没有设置。由于我的应用程序在浏览器中的作品,我觉得这不可能是安全组。我也试着与激活的virtualenv访问的变量。

However, this doesn't work when I login on the EC2 instance with SSH. The RDS environment variables are not set. Since my application works in the browser, I think it cannot be the security groups. I've also tried to access the variables with the virtualenv activated.

我怎样才能使弹性青苗时,我有一个SSH连接来定义这些变量?

How can I make elastic beanstalk to define these variables when I have an SSH connection?

推荐答案

我想通了这morgning:

I figured it out this morgning:

环境变量没有设置的virtualenv内,而是由另一个脚本。首先,你必须激活virualenv,那么你需要通过激活的 ENV加载变量的在当前目录的脚本。像这样的:

The environment variables are not set within the virtualenv, but by another script. First you have to activate the virualenv, then you need to load the variables by activating the env script in the 'current' directory. Like this:

source /opt/python/run/venv/bin/activate
source /opt/python/current/env

魔豆RDS变量现在设置,并准备好您的SSH执行任何脚本使用。

The Beanstalk RDS variables are now set and ready to use by any script you execute in SSH.