dongzhuo8210 2019-01-18 03:14
浏览 61
已采纳

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

I can't figure out how to delete hosted zone resource record set with Amazon PHP sdk.

So my code is following

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>
        ]
    ]);
}

And this is my function for deleting resource record set

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();
}

And the error I'm keep getting is

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>

So what exactly is minimum required set of params so I will be available to delete resource record from hosted zone? If you need any additional informations, please let me know and I will provide. Thank you

展开全部

  • 写回答

1条回答 默认 最新

  • doulu6929 2019-01-18 03:25
    关注

    Ok I have figure it out. If you wan't to delete resource record set from hosted zones, then the code/function for deleting record set should look like following

    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
        ]);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了