在Amazon上使用PHP删除托管区域资源记录集

时间:2019-01-18 11:14:55

标签: php aws-sdk aws-php-sdk

我不知道如何使用Amazon PHP sdk删除托管区域资源记录集。

所以我的代码在后面

public function __construct(\ConsoleOutput $stdout = null, \ConsoleOutput $stderr = null, \ConsoleInput $stdin = null) {
    parent::__construct($stdout, $stderr, $stdin);

    /** @var \Aws\Route53\Route53Client route53Client */
    $this->route53Client = Route53Client::factory([
        'version'     => '2013-04-01',
        'region'      => 'eu-west-1',
        'credentials' => [
            'key'    => <my-key>,
            'secret' => <my-secret-key>
        ]
    ]);
}

这是我删除资源记录集的功能

private function deleteResourceRecordSet() {

    $response = $this->route53Client->changeResourceRecordSets([
        'ChangeBatch'  => [
            'Changes' => [
                [
                    'Action'            => 'DELETE',
                    'ResourceRecordSet' => [
                        'Name'            => 'pm-bounces.subdomain.myDomain.com.',
                        'Region'          => 'eu-west-1',
                        'Type'            => 'CNAME',
                    ],
                ]
            ]
        ],
        'HostedZoneId' => '/hostedzone/<myHostedZoneId>'
    ]);
    var_dump($response);
    die();
}

我一直遇到的错误是

Error executing "ChangeResourceRecordSets" on "https://route53.amazonaws.com/2013-04-01/hostedzone/<myHostedZoneId>/rrset/"; AWS HTTP error: Client error: `POST https://route53.amazonaws.com/2013-04-01/hostedzone/<myHostedZoneId>/rrset/` resulted in a `400 Bad Request` response:
<?xml version="1.0"?>
<ErrorResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><Error><Type>Sender</Type><Co (truncated...)
 InvalidInput (client): Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found none in Change with [Action=DELETE, Name=pm-bounces.subdomain.myDomain.com., Type=CNAME, SetIdentifier=null] - <?xml version="1.0"?>
<ErrorResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><Error><Type>Sender</Type><Code>InvalidInput</Code><Message>Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found none in Change with [Action=DELETE, Name=pm-bounces.subdomain.myDomain.com., Type=CNAME, SetIdentifier=null]</Message>

那么最低要求的参数集到底是什么,这样我才能从托管区域删除资源记录?如果您需要任何其他信息,请告诉我,我会提供。谢谢

1 个答案:

答案 0 :(得分:0)

好,我知道了。如果您不想从托管区域中删除资源记录集,那么用于删除记录集的代码/功能应如下所示

private function deleteResourceRecordSet($zoneId, $name, $ResourceRecordsValue, $recordType, $ttl) {

    $response = $this->route53Client->changeResourceRecordSets([
        'ChangeBatch'  => [
            'Changes' => [
                [
                    'Action'            => 'DELETE',
                    "ResourceRecordSet" => [
                        'Name'            => $name,
                        'Type'            => $recordType,
                        'TTL'             => $ttl,
                        'ResourceRecords' => [
                            $ResourceRecordsValue // should be reference array of all resource records set
                        ]
                    ]
                ]
            ]
        ],
        'HostedZoneId' => $zoneId
    ]);
}