AWS Java SDK:使用新的RDS实例信息更新Route53区域记录 [英] AWS Java SDK: updating a Route53 zone record with new RDS instance info

查看:130
本文介绍了AWS Java SDK:使用新的RDS实例信息更新Route53区域记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处使用AWS Java SDK的Java 8.我有一个私有托管区域(PHZ),例如 myapp.example.com ,并且在该区域中有一个 A 记录,称为 db.myapp.example..com 指向RDS实例.

Java 8 using the AWS Java SDK here. I have a private hosted zone (PHZ) of, say, myapp.example.com and I have an A record in that zone called db.myapp.example.com which points to an RDS instance.

我现在正在编写Lambda(Java),它将创建一个新的RDS实例,并更新 db.myapp.example.com 区域记录以指向新的RDS实例.

I am now writing a Lambda (Java) that will create a new RDS instance, and update the db.myapp.example.com zone record to point to the new RDS instance.

到目前为止,我的代码的要旨如下:

So far the gist of my code looks like this:

CreateDBInstanceRequest createDbRequest = getSomehow();
DBInstance rdsInstance = amazonRDS.createDBInstance(createDbRequest);

ListHostedZonesResult hostedZonesResult = amazonRoute53.listHostedZones();
Optional<HostedZone> hostedZoneOpt = hostedZonesResult.getHostedZones().stream()
    .filter(zone -> "db.myapp.example.com".equals(zone.getName())).findFirst();
if (hostedZoneOpt.isPresent()) {

    // TODO: how to update the record so that it points to 'rdsInstance'?
    ResourceRecordSet alias = new ResourceRecordSet(aliasName, "A");
    
    Change updateAlias = new Change(ChangeAction.UPSERT, alias);
    List<Change> changes = Collections.singletonList(updateAlias);
    ChangeBatch changeBatch = new ChangeBatch(changes);

    ChangeResourceRecordSetsRequest changeRecordRequest =
        new ChangeResourceRecordSetsRequest(hostedZoneOpt.get().getId(), changeBatch);
    amazonRoute53.changeResourceRecordSets(changeRecordRequest);
    
} else {
  // handle
}

我认为这在大多数情况下是正确的.但是,在搜寻之后,

I think this is correct for the most part. However, after scouring the Route53 SDK API docs I cannot for the life of me figure out how/where I configure the alias : ResourceRecordSet instance with the new RDS (rdsInstance) info so that db.myapp.example.com now points to it.

有什么想法吗?预先感谢!

我看到Route53中有 TrafficPolicy 的概念,显然我可以将JSON文档发送到AWS并为A记录配置流量策略,所以也许这是正确的方法.但是请查看交通政策文档定义,我需要能够在其 Value 字段中指定IP地址,而且我不认为AWS开发工具包会在任何地方公开IP地址!

I see there is the concept of TrafficPolicy in Route53 and apparently I can send a JSON document to AWS and configure a traffic policy for my A record, so maybe this is the correct way to go. But looking at the Traffic Policy document definition, I need to be able to specify an IP address in its Value field, and I don't believe the AWS SDK exposes IP addresses anywhere!

推荐答案

根据

Per the AWS docs on alias routing, you can't create an alias DNS record pointing to an RDS instance. What you can do, however, is create a regular CNAME record in Route 53, pointing to the RDS instance's domain name. Your record would have type CNAME, Name db.myapp.example.com, and the Value would be the RDS instance's domain name, i.e. some-instance.cxu5ec943k5u.us-east-1.rds.amazonaws.com. You can get this from rdsInstance.getEndpoint().getAddress().

这篇关于AWS Java SDK:使用新的RDS实例信息更新Route53区域记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆