AWS Python SDK | Route 53 - delete resource record

2024/10/13 1:23:41

How to delete a DNS record in Route 53? I followed the documentation but I still can't make it work. I don't know if I'm missing something here.

Based on the documentation:

DELETE : Deletes a existing resource record set that has the specifiedvalues for Name , Type , SetIdentifier (for latency, weighted,geolocation, and failover resource record sets), and TTL (except aliasresource record sets, for which the TTL is determined by the AWSresource that you're routing DNS queries to).

But I'm always getting this error:

Traceback (most recent call last):                                                                                                                                      File "./test.py", line 37, in <module>                                                                                                                                main()                                                                                                                                                              File "./test.py", line 34, in main                                                                                                                                    print(del_record())                                                                                                                                                 File "./test.py", line 23, in del_record                                                                                                                              'TTL': 300                                                                                                                                                          File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/botocore/client.py", line 251, in _api_call                                       return self._make_api_call(operation_name, kwargs)                                                                                                                  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/botocore/client.py", line 537, in _make_api_call                                  raise ClientError(parsed_response, operation_name)                                                                                                                  
botocore.exceptions.ClientError: An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid request 

Here's my code:

#!/usr/bin/env python3import boto3r53 = boto3.client('route53')
zone_id = 'ABCDEFGHIJKLMNO'
record = 'me.domain.com'
r_type = 'CNAME'
r_val = 'google.com'def del_record():response = r53.change_resource_record_sets(HostedZoneId=zone_id,ChangeBatch={'Changes': [{'Action': 'DELETE','ResourceRecordSet': {'Name': record,'Type': r_type,'TTL': 300}}]})return responsedef main():print(del_record())if __name__ == '__main__':main()
Answer

You need a nested 'ResourceRecords' array in the ResourceRecordSet, which has the current 'target' value of the record.

    HostedZoneId=zone_id,ChangeBatch={'Changes': [{'Action': 'DELETE','ResourceRecordSet': {'Name': record,'Type': r_type,'TTL': 300,'ResourceRecords': [{'Value': target}]}}]}
https://en.xdnf.cn/q/69586.html

Related Q&A

How can I change to gt; and gt; to ? [duplicate]

This question already has answers here:Decode HTML entities in Python string?(7 answers)Closed 8 years ago.print u<How can I print <print > How can I print >

basemap: How to remove actual lat/lon lines while keeping the ticks on the axis

I plotted a map by basemap as below:plt.figure(figsize=(7,6)) m = Basemap(projection=cyl,llcrnrlat=40.125,urcrnrlat=44.625,\llcrnrlon=-71.875,urcrnrlon=-66.375,resolution=h) m.drawparallels(np.arange(i…

Re-initialize variables in Tensorflow

I am using a Tensorflow tf.Saver to load a pre-trained model and I want to re-train a few of its layers by erasing (re-initializing to random) their appropriate weights and biases, then training those …

Python: invert image with transparent background (PIL, Gimp,...)

I have a set of white icons on transparent background, and Id like to invert them all to be black on transparent background. Have tried with PIL (ImageChops) but it does not seem to work with transpare…

vlookup between 2 Pandas dataframes

I have 2 pandas Dataframes as follows.DF1:Security ISIN ABC I1 DEF I2 JHK I3 LMN I4 OPQ I5and DF2:ISIN ValueI2 100I3 200I5 …

replacing quotes, commas, apostrophes w/ regex - python/pandas

I have a column with addresses, and sometimes it has these characters I want to remove => - " - ,(apostrophe, double quotes, commas)I would like to replace these characters with space in one s…

Reading text from image

Any suggestions on converting these images to text? Im using pytesseract and its working wonderfully in most cases except this. Ideally Id read these numbers exactly. Worst case I can just try to u…

XGBoost and sparse matrix

I am trying to use xgboost to run -using python - on a classification problem, where I have the data in a numpy matrix X (rows = observations & columns = features) and the labels in a numpy array y…

How to preserve form fields in django after unsuccessful submit?

Code from views.py:def feedback(request):if request.method == "POST":form = CommentForm(request.POST)if form.is_valid():form.save()else:print("form.errors:", form.errors)else:form =…

Idiomatic way to parse POSIX timestamps in pandas?

I have a csv file with a time column representing POSIX timestamps in milliseconds. When I read it in pandas, it correctly reads it as Int64 but I would like to convert it to a DatetimeIndex. Right now…