【发布时间】:2026-01-25 03:10:01
【问题描述】:
我正在尝试启动一个 Aurora Postgres 集群,但我似乎无法通过 Internet 提供它。我正在使用 Terraform 对基础架构进行编码。
我创建了一个安全组以允许外部访问,并且它附加到集群使用的 VPC 子网。不过,我似乎无法从本地机器访问端点。
我不知道我错过了什么。
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = ">=3.11.0"
name = "vpc-auroradb-${var.environment}"
cidr = var.vpc_cidr_block
azs = var.availability_zones
private_subnets = var.vpc_private_subnets
public_subnets = var.vpc_public_subnets
database_subnets = var.vpc_database_subnets
enable_nat_gateway = true
enable_dns_hostnames = true
enable_dns_support = true
create_igw = true
create_database_internet_gateway_route = true
create_database_nat_gateway_route = true
create_database_subnet_group = true
create_database_subnet_route_table = true
}
module "aurora_cluster" {
source = "terraform-aws-modules/rds-aurora/aws"
version = ">=6.1.3"
name = "bambi-${var.environment}"
engine = "aurora-postgresql"
engine_version = "12.8"
instance_class = "db.t4g.large"
publicly_accessible = true
instances = {
1 = {
identifier = "bambi-1"
}
2 = {
identifier = "bambi-2"
}
}
autoscaling_enabled = true
autoscaling_min_capacity = 2
autoscaling_max_capacity = 3
vpc_id = module.vpc.vpc_id
db_subnet_group_name = module.vpc.database_subnet_group_name
create_db_subnet_group = false
create_security_group = false
iam_database_authentication_enabled = true
storage_encrypted = true
apply_immediately = true
monitoring_interval = 30
db_parameter_group_name = aws_db_parameter_group.parameter_group.id
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.parameter_group.id
vpc_security_group_ids = [aws_security_group.sg_public.id]
enabled_cloudwatch_logs_exports = ["postgresql"]
}
resource "aws_security_group" "sg_public" {
vpc_id = module.vpc.vpc_id
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # Allowing traffic in from all sources
}
egress {
from_port = 0 # Allowing any incoming port
to_port = 0 # Allowing any outgoing port
protocol = "-1" # Allowing any outgoing protocol
cidr_blocks = ["0.0.0.0/0"] # Allowing traffic out to all IP addresses
}
}
【问题讨论】:
-
您得到的确切错误是什么?网络超时?你的地形对我来说看起来是正确的。您可能想要登录 AWS Web 控制台并仔细检查 Aurora 实例是否正在运行,并且公共可访问性功能已实际启用。我认为您可能会遇到问题,因为您同时启用了
create_database_nat_gateway_route和create_database_internet_gateway_route。这些设置相互冲突。您应该禁用数据库 NAT 网关路由。 -
感谢指点!事实上,正如您所提到的以及下面详述的 Ervin,我确实在我的 VPC 模块上启用了两个相互冲突的设置。谢谢!
标签: postgresql amazon-web-services terraform amazon-rds amazon-aurora