aws-samples / aws-lambda-ddns-function

Dynamically create Route 53 resource records using CloudWatch Events and Lambda
Apache License 2.0
236 stars 116 forks source link

Support Python 3.9 #40

Open lefjul opened 2 years ago

lefjul commented 2 years ago

With Python 3.9 I get this error when the lambda must remove a record from the hosted zone (when stopping a EC2 instance) :

[ERROR] JSONDecodeError: Expecting value: line 1 column 2402 (char 2401)
Traceback (most recent call last):
  File "/var/task/union_python3.py", line 167, in lambda_handler
    instance = get_item_from_dynamodb_table(dynamodb_client, 'DDNS', instance_id)
  File "/var/task/union_python3.py", line 1069, in get_item_from_dynamodb_table
    return json.loads(item)
  File "/var/lang/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/var/lang/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/var/lang/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

I don't face any error with Python 3.6 runtime. Since Python 3.6 will be deprecated in AWS on 18/07/2022, could you please bring the support of Python 3.9 ?

Thanks

lefjul commented 2 years ago

I get this error with the python 3.7 runtime as well :

[ERROR] JSONDecodeError: Expecting value: line 1 column 2385 (char 2384)
Traceback (most recent call last):
  File "/var/task/union_python3.py", line 167, in lambda_handler
    instance = get_item_from_dynamodb_table(dynamodb_client, 'DDNS', instance_id)
  File "/var/task/union_python3.py", line 1069, in get_item_from_dynamodb_table
    return json.loads(item)
  File "/var/lang/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/var/lang/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/var/lang/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
abjoerne commented 2 years ago

I have not dived into this, but are using a slightly modified version (no reverse lookup zones) of the v3-python-file. It works well with both python 3.6 and 3.9

lefjul commented 2 years ago

To solve this issue I added these 2 lines of code after the line numbered 1067 :

            # BEGIN FIX JSON DECODE
            item = item.replace(" True}", ' "True"}')
            item = item.replace(" False}", ' "False"}')
            # END FIX JSON DECODE

Now it is OK.

lefjul commented 2 years ago

@abjoerne : could please tell me how you modified the code to disable the reverse lookup zones ? I'm interested in as well,

Thanks, Lefjul

abjoerne commented 2 years ago

I just removed all code related to the reverse zones as well as some other adjustments to fit our needs.

nindza commented 5 months ago

I can confirm @lefjul solution works in Mar/2024 with Python 3.12.