简体   繁体   English

Zappa + RDS 连接问题

[英]Zappa + RDS Connection Issues

I'm hoping someone could help me out with some questions regarding VPC.我希望有人可以帮助我解决有关 VPC 的一些问题。 I'm pretty new to AWS and I'm just trying to build a sample web app to get my feet wet with everything.我对 AWS 还很陌生,我只是想构建一个示例 Web 应用程序,让我对所有东西都感到满意。 I've been roughly following this guide to try and setup a basic project using Zappa + Django.我一直在粗略地遵循本指南来尝试使用 Zappa + Django 设置一个基本项目。 I've gotten to the state where I'm configuring a VPC and trying to add a Postgres instance that Django/zappa can talk to.我已经到了配置 VPC 并尝试添加 Django/zappa 可以与之通信的 Postgres 实例的状态。 Per that article, I've setup up my network like this:根据那篇文章,我已经像这样设置了我的网络:

  • Internet Gateway attached to VPC连接到 VPC 的 Internet 网关
  • 4 Public subnets 4 个公共子网
  • 4 Private subnets 4 个私有子网
  • Lambda function in 2 of the private subnets 2 个私有子网中的 Lambda 函数
  • RDS with subnet group in other 2 private subnets RDS 在其他 2 个私有子网中具有子网组
  • EC2 box in 1 public subnet that allows SSH from my local IP to forward port 5432 to RDS instance 1 个公共子网中的 EC2 盒,允许 SSH 从我的本地 IP 将端口 5432 转发到 RDS 实例

My issue comes when I try and run migrations on my local machine using "python manage.py makemigrations".当我尝试使用“python manage.py makemigrations”在本地机器上运行迁移时,我的问题就出现了。 I keep getting an error that says "Is the server running on host "zappadbinstance.xxxxx.rds.amazonaws.com" (192.168.x.xxx) and accepting TCP/IP connections on port 5432?".我不断收到一条错误消息,指出“服务器是否在主机“zappadbinstance.xxxxx.rds.amazonaws.com”(192.168.x.xxx)上运行并接受端口 5432 上的 TCP/IP 连接?”。

I'm not sure what step I'm missing.我不确定我错过了什么步骤。 I followed this guide and this post to setup the bastion host, and I know it is working because I am able to (1) ssh from my terminal and (2) establish a database connection using PSequel on my local machine.我按照本指南这篇文章来设置堡垒主机,我知道它正在工作,因为我能够 (1) 从我的终端 ssh 和 (2) 在我的本地机器上使用 PSquel 建立数据库连接。

I feel like I'm really close but I must be missing something.我觉得我真的很接近,但我一定错过了一些东西。 Any help or pointers would be greatly appreciated.任何帮助或指示将不胜感激。

First, nice job on getting this set up - it's quite a challenge.首先,在设置这个方面做得很好 - 这是一个相当大的挑战。 I agree with you that you're almost there.我同意你的看法,你快到了。 Since you can connect with PSequel from your local system, that validates that your machine is accurately connected to the VPC RDS from a network perspective.由于您可以从本地系统连接 PSquel,因此可以从网络角度验证您的机器是否准确连接到 VPC RDS。

Next area to look at is the Django setup.下一个要查看的区域是 Django 设置。 If the local machine Django settings are incorrect, this would cause the error.如果本地机器 Django 设置不正确,则会导致错误。 So your database section in your settings file should be different on the local machine.所以你的设置文件中的数据库部分在本地机器上应该是不同的。 As you describe in one of your comments above, I believe you have 'HOST': 'xxxxx.us-east-2.rds.amazonaws.com' When you run python manage.py makemigrations , django attempts to use that host name and connect to it.正如您在上面的评论之一中所描述的,我相信您有'HOST': 'xxxxx.us-east-2.rds.amazonaws.com'当您运行python manage.py makemigrations ,django 尝试使用该主机名并连接到它。 Unfortunately, this bypasses your carefully constructed ssh tunnel.不幸的是,这绕过了您精心构建的 ssh 隧道。

To fix this, you can either:要解决此问题,您可以:

  1. Edit your local settings.py to have 'HOST':'127.0.0.1'编辑您的本地 settings.py 以具有'HOST':'127.0.0.1'
  2. Edit your /etc/hosts file to point to the FQDN above (but I wouldn't recommend this since often I forget to remove the edits)编辑您的/etc/hosts文件以指向上面的 FQDN(但我不建议这样做,因为我经常忘记删除编辑)

Should be easy enough to try #1 above and see if that works.应该很容易尝试上面的#1,看看是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM