awslabs / route53-dynamic-dns-with-lambda

A Dynamic DNS system built with API Gateway, Lambda & Route 53.
Apache License 2.0
486 stars 167 forks source link

Some requests are base64 encoded, breaking the function #54

Closed andrew-stclair closed 3 months ago

andrew-stclair commented 7 months ago

Hello,

It seems that some (not all) requests to the lambda function get base64 encoded, breaking the function and causing a 502 error.

I've done some digging and found that requests that work are like this:

{
  ...
  "body": "{\"execution_mode\": \"get\"}",
  "isBase64Encoded": "False"
}

But sometimes instead i get this:

{
  ...
  "body": "J3tleGVjdXRpb25fbW9kZTpnZXR9Jw==",
  "isBase64Encoded": "True"
}

If i add some code to decode that base64, it returns invalid json:

'{execution_mode:get}'
masberta commented 7 months ago

Hello,

It seems that some (not all) requests to the lambda function get base64 encoded, breaking the function and causing a 502 error.

I've done some digging and found that requests that work are like this:

{
  ...
  "body": "{\"execution_mode\": \"get\"}",
  "isBase64Encoded": "False"
}

But sometimes instead i get this:

{
  ...
  "body": "J3tleGVjdXRpb25fbW9kZTpnZXR9Jw==",
  "isBase64Encoded": "True"
}

If i add some code to decode that base64, it returns invalid json:

'{execution_mode:get}'

thanks @andrew-stclair is this happening with the same request getting this inconsistent behavior or is there a specific DNS name causing this? Do you have any non alphanumeric character in your domain name?

andrew-stclair commented 7 months ago

Same request, always the first one it seems, subsequent requests seem to work as expected. I think it may be related to cold starts.

DNS address has standard english characters in it, nothing non alphanumeric.

I have made a temporary workaround by doing two get calls to the lambda, ignoring the first one.

masberta commented 6 months ago

Same request, always the first one it seems, subsequent requests seem to work as expected. I think it may be related to cold starts.

DNS address has standard english characters in it, nothing non alphanumeric.

I have made a temporary workaround by doing two get calls to the lambda, ignoring the first one.

I will try to replicate the issue, can you confirm which Python runtime is set on your Lambda function? Also, do you use the provided bash script to call the function or you use another method?

andrew-stclair commented 6 months ago

My lambda function is on python 3.12

And i'm using the provided script, but first calling the lambda function via a get request before doing so.

masberta commented 3 months ago

cannot replicate