dongzhuo8210 2019-01-18 11: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 11: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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)