代码之家  ›  专栏  ›  技术社区  ›  Valor_ user3379466

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

  •  0
  • Valor_ user3379466  · 技术社区  · 6 年前

    我不知道如何删除使用AmazonPHP 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 回复  |  直到 6 年前
        1
  •  0
  •   Valor_ user3379466    6 年前

    好吧,我已经想好了。如果您不想从托管区域中删除资源记录集,那么用于删除记录集的代码/函数应该如下所示

    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
        ]);
    }
    
    推荐文章