是否可以使用AWS PHP SDK向Route53添加子域? [英] Is it possible to add a subdomain to Route53 using the AWS PHP SDK?

查看:59
本文介绍了是否可以使用AWS PHP SDK向Route53添加子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我们将在Route53中创建子域和域.我们希望有一种以编程方式执行此操作的方法.用于PHP的SDK文档的文档似乎有些许困难,但看来createHostedZone可用于创建域或子域记录,而changeResourceRecordSets可用于创建必要的DNS记录.有没有人举例说明如何实现这一目标?

I am working on a project where we will be creating both subdomains as well as domains in Route53. We are hoping that there is a way to do this programmatically. The SDK for PHP documentation seems a little light, but it appears that createHostedZone can be used to create a domain or subdomain record and that changeResourceRecordSets can be used to create the DNS records necessary. Does anyone have examples of how to actually accomplish this?

推荐答案

是的,如您已经指出的,可以使用changeResourceRecordSets调用来实现.但这有点笨拙,因为即使您仅更改/创建一个记录,甚至创建就是更改,都必须像批处理一样构造它.这是一个完整的示例,没有凭证方法:

Yes, this is possible using the changeResourceRecordSets call, as you already indicated. But it is a bit clumsy since you have to structure it like a batch even if you're changing/creating only one record, and even creations are changes. Here is a full example, without a credentials method:

<?php

// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';

use Aws\Route53\Route53Client;
use Aws\Common\Credentials\Credentials;

$client = Route53Client::factory(array(
    'credentials' => $credentials
));

$result = $client->changeResourceRecordSets(array(
    // HostedZoneId is required
    'HostedZoneId' => 'Z2ABCD1234EFGH',
    // ChangeBatch is required
    'ChangeBatch' => array(
        'Comment' => 'string',
        // Changes is required
        'Changes' => array(
            array(
                // Action is required
                'Action' => 'CREATE',
                // ResourceRecordSet is required
                'ResourceRecordSet' => array(
                    // Name is required
                    'Name' => 'myserver.mydomain.com.',
                    // Type is required
                    'Type' => 'A',
                    'TTL' => 600,
                    'ResourceRecords' => array(
                        array(
                            // Value is required
                            'Value' => '12.34.56.78',
                        ),
                    ),
                ),
            ),
        ),
    ),
));

可以在此处.您需要非常仔细地注意必填字段以及其他字段的可能值.例如,name字段必须是以点(.)结尾的FQDN.

The documentation of this method can be found here. You'll want to take very careful note of the required fields as well as the possible values for others. For instance, the name field must be a FQDN ending with a dot (.).

还值得注意的是:默认情况下,此调用后您没有收到来自API的响应,即没有确认或交易ID. (尽管如果有问题,它肯定会返回错误.)因此,这意味着如果您希望代码是防弹的,则应编写一个Guzzle响应处理程序,并且可能要等待几秒钟,然后运行检查新代码./更改的记录确实存在.

Also worth noting: You get no response back from the API after this call by default, i.e. there is no confirmation or transaction id. (Though it definitely gives errors back if something is wrong.) So that means that if you want your code to be bulletproof, you should write a Guzzle response handler AND you may want to wait a few seconds and then run a check that the new/changed record indeed exists.

希望这会有所帮助!

这篇关于是否可以使用AWS PHP SDK向Route53添加子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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