0

我已成功将一个 VPC ( ) 中的两个子网对等B连接到另一个 VPC ( A)。但是,我在其中创建的私有路由 53 DNS 条目B并未应用于我在其中部署的 AWS Lambda 函数A

如何从 VPC 获取 DNS 条目B以在 VPC 中工作A

(TF片段)

# VPCs
resource "aws_vpc" "a" {
  cidr_block = "192.16.0.0/16"

  enable_dns_support   = true
  enable_dns_hostnames = true

  tags = {
    Name = "A"
  }
}

resource "aws_vpc" "b" {
  cidr_block = "10.16.0.0/16"

  enable_dns_support   = true
  enable_dns_hostnames = true

  tags = {
    Name = "B"
  }
}

# Subnets
resource "aws_subnet" "b_peer_region_a" {
  vpc_id     = aws_vpc.b.id
  cidr_block = "10.16.64.0/24"

  availability_zone = "${var.aws_region}a"

  tags = {
    Name = "B Peer Region A"
  }
}

resource "aws_subnet" "b_peer_region_b" {
  vpc_id     = aws_vpc.b.id
  cidr_block = "10.16.96.0/24"

  availability_zone = "${var.aws_region}b"

  tags = {
    Name = "B Peer Region B"
  }
}

# Peering
resource "aws_vpc_peering_connection" "a_b" {
  vpc_id      = aws_vpc.b.id
  peer_vpc_id = aws_vpc.a.id
  auto_accept = true

  accepter {
    allow_remote_vpc_dns_resolution = true
  }

  requester {
    allow_remote_vpc_dns_resolution = true
  }

  tags = {
    Name = "a-b"
  }
}

resource "aws_vpc_peering_connection_accepter" "a_b" {
  vpc_peering_connection_id = aws_vpc_peering_connection.a_b.id
  auto_accept               = true

  tags = {
    Name = "a-b"
  }
}

# DNS
resource "aws_route53_zone" "private_b" {
  name = "internal.example.com"

  vpc {
    vpc_id = aws_vpc.b.id
  }
}

resource "aws_route53_record" "private_b_rds" {
  zone_id = aws_route53_zone.private_b.zone_id
  name    = "rds.internal.example.com"
  type    = "CNAME"
  ttl     = "300"
  records = [
    aws_db_instance.rds.address
  ]
}
4

0 回答 0