Repository: aws-powertools/powertools-lambda-python

Issue:
DeprecationWarning for distutils in Python 3.10 (will be removed in Python 3.12)
<!--- Provide a general summary of the issue in the Title above -->
<!--- How has this issue affected you? What are you trying to accomplish? -->

**What were you trying to accomplish?**

Run tests utilizing aws-lambda-powertools.

## Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->

No DeprecationWarning to appear.

## Current Behavior
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->

When running tests (specifically using `pytest`) that import `aws_lamdba_powertools`, a `DeprecationWarning` appears.

```
.../aws_lambda_powertools/shared/functions.py:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
    from distutils.util import strtobool
```

## Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement the addition or change -->

The only function used out of distutils is `strtobool`, and it is only used in one place, so that logic can simply be copied into the `resolve_truthy_env_var_choice` function in `aws_lambda_powertools.shared.functions`.

## Steps to Reproduce (for bugs)
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
<!--- reproduce this bug. Include code to reproduce, if relevant -->
1. Use python3.10
2. Activate a new venv (`python3.10 -m venv .venv` and `. .venv/bin/activate`)
3. `pip install aws-lambda-powertools pytest`
4. `echo "import aws_lambda_powertools" > reproduce.py`
5. `pytest reproduce.py`

## Environment

* **Powertools version used**: `1.22.0`
* **Packaging format (Layers, PyPi)**: PyPi

This warning appears in development workflows, but will be eventually breaking when Python 3.12 is released.


Discussion:
Thanks for opening your first issue here! We'll come back to you as soon as we can.

It will be tricky to support both 3.6 and 3.12 at the same time

By the time 3.10 runtime is officially launched, python 3.6 would be deprecated?
@nayaverdier thanks for raising the issue.

Lambda runtime does not support 3.10 yet hence why this hasn't been actioned. 
Would a PR on this be helpful or would it not be considered until 3.10 (or 3.12) is a supported lambda runtime?
@nayaverdier 3.10 support comes sooner ;) 
> Would a PR on this be helpful or would it not be considered until 3.10 (or 3.12) is a supported lambda runtime?

I'd love a PR! I would take any help I can get ;-)

Resolving patch:
diff --git a/aws_lambda_powertools/shared/functions.py b/aws_lambda_powertools/shared/functions.py
--- a/aws_lambda_powertools/shared/functions.py
+++ b/aws_lambda_powertools/shared/functions.py
@@ -1,7 +1,16 @@
-from distutils.util import strtobool
 from typing import Any, Optional, Union
 
 
+def strtobool(value):
+    value = value.lower()
+    if value in ("y", "yes", "t", "true", "on", "1"):
+        return 1
+    elif value in ("n", "no", "f", "false", "off", "0"):
+        return 0
+    else:
+        raise ValueError("invalid truth value %r" % (value,))
+
+
 def resolve_truthy_env_var_choice(env: str, choice: Optional[bool] = None) -> bool:
     """Pick explicit choice over truthy env value, if available, otherwise return truthy env value
 


Test patch: