【发布时间】:2021-11-05 02:46:56
【问题描述】:
我有一个使用 awsebcli 在 AWS 上部署的 django 项目。
我需要提供一个数据库(postgres),一旦部署了环境,我就从控制台创建一个数据库 我想自动化这个过程,我尝试了一个配置文件
所以我尝试将其添加到项目的 .ebextensions 文件夹中的 django.config 文件中:
aws:rds:dbinstance:
DBAllocatedStorage: '5'
DBDeletionPolicy: Delete
DBEngine: postgres
DBEngineVersion: 10.17
DBInstanceClass: db.t2.micro
DBPassword: PASSWORD_HERE
DBUser: USERNAME_HERE
MultiAZDatabase: false
但是这种方式并没有创建数据库。我必须从控制台创建它,然后使用终端(eb setenv)将数据库的端点和其他参数作为环境变量传递。
有没有办法解决这个问题并使部署自动化?
-----编辑----- 这是我完整的 django.config 文件
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "personal_portfolio.settings"
PYTHONPATH: "/var/app/current:$PYTHONPATH"
AWS_STORAGE_BUCKET_NAME: "insert-bucketname"
AWS_S3_REGION_NAME: "us-east-1"
RDS_USERNAME: "xxxx"
RDS_PASSWORD: "xxxx"
aws:elasticbeanstalk:container:python:
WSGIPath: "personal_portfolio.wsgi:application"
NumProcesses: 3
NumThreads: 20
aws:elasticbeanstalk:environment:process:default:
HealthCheckPath: "/about"
MatcherHTTPCode: "200-499"
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
/media: media
aws:rds:dbinstance:
DBAllocatedStorage: 5
DBDeletionPolicy: Delete
DBEngine: postgres
DBEngineVersion: 10.17
DBInstanceClass: db.t2.micro
DBPassword: lorokpopen
DBUser: postgres
MultiAZDatabase: false
container_commands:
01_makemigrations:
command: "source /var/app/venv/*/bin/activate && python3 manage.py makemigrations --noinput"
leader_only: true
02_migrate:
command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate --noinput"
leader_only: true
03_createsu:
command: "source /var/app/venv/*/bin/activate && python3 manage.py createsu"
04_collectstatic:
command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput"
leader_only: true
【问题讨论】:
标签: django postgresql amazon-web-services amazon-elastic-beanstalk