简体   繁体   English

PostgreSQL 连接尝试超时错误的 AWS RDS

[英]AWS RDS for PostgreSQL Connection attempt timed out error

I created postgresql rds in aws with terraform. I'm checking from the aws console, everything seems normal.我用 terraform 在 aws 中创建了 postgresql rds。我正在从 aws 控制台检查,一切似乎都很正常。 But I'm trying to connect to database with DBeaver but I can't connect.但是我正在尝试使用 DBeaver 连接到数据库,但我无法连接。 Likewise, I can't make the ssh connection for the ec2 I created, maybe there is a connection.同样,我无法为我创建的 ec2 建立 ssh 连接,也许有连接。 The terraform codes I wrote:我写的terraform代码:

# postgres-db/main.tf
resource "aws_db_instance" "default" {
  allocated_storage      = 20
  storage_type           = "gp2"
  engine                 = var.engine
  engine_version         = var.engine-version
  instance_class         = var.instance-class
  db_name                = var.db-name
  identifier             = var.identifier
  username               = var.username
  password               = var.password
  port                   = var.port
  publicly_accessible    = var.publicly-accessible
  db_subnet_group_name   = var.db-subnet-group-name
  parameter_group_name   = var.parameter-group-name
  vpc_security_group_ids = var.vpc-security-group-ids
  apply_immediately      = var.apply-immediately
  skip_final_snapshot    = true
}

module "service-db" {
  source = "./postgres-db"

  apply-immediately      = true
  db-name                = var.service-db-name
  db-subnet-group-name   = data.terraform_remote_state.server.outputs.db_subnet_group
  identifier             = "${var.app-name}-db"
  password               = var.service-db-password
  publicly-accessible    = true # TODO: True for now, but should be false
  username               = var.service-db-username
  vpc-security-group-ids = [data.terraform_remote_state.server.outputs.security_group_allow_internal_postgres]
}
resource "aws_security_group" "allow_internal_postgres" {
  name        = "allow-internal-postgres"
  description = "Allow internal Postgres traffic"
  vpc_id      = aws_vpc.vpc.id

  ingress {
    from_port   = 5432
    to_port     = 5432
    protocol    = "tcp"
    cidr_blocks = [aws_vpc.vpc.cidr_block, "0.0.0.0/0"] # TODO: Remove public IP
  }
}

In the research I did, it was written things like edit the security rules or set it to public, it seems like that anyway.在我做的研究中,它写了一些东西,比如编辑安全规则或将其设置为公开,反正看起来是这样。

Security group inbound rules安全组入站规则

Public accessible公众可访问

How can I solve this problem can you please help?我该如何解决这个问题,你能帮忙吗?

I solved my problem by setting the su.net group to public.我通过将 su.net 组设置为公开解决了我的问题。

module "service-db" {
  source = "./postgres-db"

  apply-immediately      = true
  db-name                = var.service-db-name
  db-subnet-group-name   = data.terraform_remote_state.server.outputs.db_subnet_group_public
  identifier             = "${var.app-name}-db"
  password               = var.service-db-password
  publicly-accessible    = true # TODO: True for now, but should be false
  username               = var.service-db-username
  vpc-security-group-ids = [data.terraform_remote_state.server.outputs.security_group_allow_internal_postgres]
}
resource "aws_db_subnet_group" "private" {
  name       = "${var.server_name}-db-subnet-group-private"
  subnet_ids = aws_subnet.private.*.id

  tags = {
    Name = "${var.server_name} DB Subnet Group Private"
  }
}
resource "aws_db_subnet_group" "public" {
  name       = "${var.server_name}-db-subnet-group-public"
  subnet_ids = aws_subnet.public.*.id

  tags = {
    Name = "${var.server_name} DB Subnet Group Public"
  }
}

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

相关问题 AWS RDS 的 Terraform Postgresql 提供程序错误:“拨号 tcp 127.0.0.1:5432:连接:连接被拒绝” - Terraform Postgresql provider error for AWS RDS: "dial tcp 127.0.0.1:5432: connect: connection refused" gsutil 错误:重试请求,尝试 #1...捕获套接字错误,重试:超时 - gsutil error: Retrying request, attempt #1... Caught socket error, retrying: timed out 如果指定了 dbi-resource-id,则使用 IAM 角色的 AWS RDS PostgreSQL 连接不起作用 - AWS RDS PostgreSQL connection using IAM Role is not working if dbi-resource-id specified 将 aws lambda 与 redis 连接时,任务在 23.02 秒错误后超时 - while connecting aws lambda with redis getting Task timed out after 23.02 seconds error CDC 和副本使用 AWS DMS 从 oracle PeopleSoft 到 RDS postgreSQL - CDC and replica using AWS DMS from oracle PeopleSoft to RDS postgreSQL gitlab CI/CD 连接超时 - gitlab CI/CD Connection timed out AWS Lambda 任务在 3.00 秒后超时 - AWS Lambda Task timed out after 3.00 seconds EC2 实例 ERR_CONNECTION_TIMED_OUT - EC2 instance ERR_CONNECTION_TIMED_OUT PostgreSQL AWS RDS 和 GCP 云之间的多主复制 SQL - PostgreSQL multi-master replication between AWS RDS and GCP Cloud SQL AWS RDS 自动备份 - AWS RDS automated backup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM