CloudFormation:访问 PrivateDnsNamespace 作为 HostedZone
CloudFormation: Access PrivateDnsNamespace as HostedZone
ServiceDiscovery::PrivateDnsNamespace
的 documentation 指出:
When you create a private DNS namespace, AWS Cloud Map automatically creates an Amazon Route 53 private hosted zone that has the same name as the namespace.
在 CloudFormation 中,是否有任何方法可以访问创建的 HostedZone
(作为 Route53::HostedZone
)以便我可以向其中添加额外的 Route53:RecordSet
?
- ID是否相同?
- 我可以添加同名的
Route53::HostedZone
以获得正确的 ID 吗?
- 还有别的技巧吗?
例如,我想在私有 DNS 条目中公开我的 RDS 和 ElastiCache (Redis) 实例。我意识到这可能是 XY 问题,但我在我的遗留代码中的标准位置访问这些系统,并在我的第一次 ECS 尝试中尽量减少定制(以及潜在的错误)。
警告:虽然 AWS 服务发现策略可用于公开 DB 和 RDS 等服务,但有几个条件:
- AWS 服务发现需要语法
<name>.<namespace>
,因此您不能简单地公开 db
和 redis
处的服务。 'standard' 域的最佳赔率类似于 redis.local
和 db.local
。虽然 local
是保留的 TLD,但对其使用存在一些敌意。
- RDS SSL certificates are tied to the RDS domain name and custom SSL certificates are not supported 所以你不能在
db.<mydomain>.com
暴露它。如果您不使用 RDS CNAME,您将无法通过受信任的 SSL 连接连接到这些实例。
无法访问在 CloudFormation 中创建的 HostedZone
。
不过,如果您想向这个私人区域添加额外的记录,您可以使用 AWS::ServiceDiscovery::Service
and AWS::ServiceDiscovery::Instance
资源。
基本上,您需要为 RDS 实例创建一项服务,为 Redis 实例创建一项服务。然后在您的服务中创建实例。
RDS 示例:
RDSSDService:
Type: AWS::ServiceDiscovery::Service
Properties:
DnsConfig:
DnsRecords:
- TTL: 60
Type: CNAME
NamespaceId:
Ref: YourNamespace
RoutingPolicy: WEIGHTED
Name: my-rds-service # this will become the record name
NamespaceId:
Ref: YourNamespace
RDSSDInstance: # If your RDS instance is in the same stack
Type: AWS::ServiceDiscovery::Instance
Properties:
InstanceAttributes:
AWS_INSTANCE_CNAME:
Fn::GetAtt:
- YourInstanceLogicalName
- Endpoint.Address
ServiceId:
Fn::GetAtt:
- RDSSDService
- Id
InstanceId: # this is optional
Ref: YourInstanceLogicalName
RDSInstance: # If referencing an existing instance
Type: AWS::ServiceDiscovery::Instance
Properties:
InstanceAttributes:
AWS_INSTANCE_CNAME: xyz.abc.us-east-1.rds.amazonaws.com # or with Fn::ImportValue
ServiceId:
Fn::GetAtt:
- RDSSDService
- Id
InstanceId: xyz # this is optional
ServiceDiscovery::PrivateDnsNamespace
的 documentation 指出:
When you create a private DNS namespace, AWS Cloud Map automatically creates an Amazon Route 53 private hosted zone that has the same name as the namespace.
在 CloudFormation 中,是否有任何方法可以访问创建的 HostedZone
(作为 Route53::HostedZone
)以便我可以向其中添加额外的 Route53:RecordSet
?
- ID是否相同?
- 我可以添加同名的
Route53::HostedZone
以获得正确的 ID 吗? - 还有别的技巧吗?
例如,我想在私有 DNS 条目中公开我的 RDS 和 ElastiCache (Redis) 实例。我意识到这可能是 XY 问题,但我在我的遗留代码中的标准位置访问这些系统,并在我的第一次 ECS 尝试中尽量减少定制(以及潜在的错误)。
警告:虽然 AWS 服务发现策略可用于公开 DB 和 RDS 等服务,但有几个条件:
- AWS 服务发现需要语法
<name>.<namespace>
,因此您不能简单地公开db
和redis
处的服务。 'standard' 域的最佳赔率类似于redis.local
和db.local
。虽然local
是保留的 TLD,但对其使用存在一些敌意。 - RDS SSL certificates are tied to the RDS domain name and custom SSL certificates are not supported 所以你不能在
db.<mydomain>.com
暴露它。如果您不使用 RDS CNAME,您将无法通过受信任的 SSL 连接连接到这些实例。
无法访问在 CloudFormation 中创建的 HostedZone
。
不过,如果您想向这个私人区域添加额外的记录,您可以使用 AWS::ServiceDiscovery::Service
and AWS::ServiceDiscovery::Instance
资源。
基本上,您需要为 RDS 实例创建一项服务,为 Redis 实例创建一项服务。然后在您的服务中创建实例。
RDS 示例:
RDSSDService:
Type: AWS::ServiceDiscovery::Service
Properties:
DnsConfig:
DnsRecords:
- TTL: 60
Type: CNAME
NamespaceId:
Ref: YourNamespace
RoutingPolicy: WEIGHTED
Name: my-rds-service # this will become the record name
NamespaceId:
Ref: YourNamespace
RDSSDInstance: # If your RDS instance is in the same stack
Type: AWS::ServiceDiscovery::Instance
Properties:
InstanceAttributes:
AWS_INSTANCE_CNAME:
Fn::GetAtt:
- YourInstanceLogicalName
- Endpoint.Address
ServiceId:
Fn::GetAtt:
- RDSSDService
- Id
InstanceId: # this is optional
Ref: YourInstanceLogicalName
RDSInstance: # If referencing an existing instance
Type: AWS::ServiceDiscovery::Instance
Properties:
InstanceAttributes:
AWS_INSTANCE_CNAME: xyz.abc.us-east-1.rds.amazonaws.com # or with Fn::ImportValue
ServiceId:
Fn::GetAtt:
- RDSSDService
- Id
InstanceId: xyz # this is optional