Skip to content

Commit dfb9892

Browse files
feat(general): add support for Python 3.11 (aws-powertools#2820)
* feat: add support for Python 3.11 * fix: remove python-snappY * fastjsonschema: test change due to behavior change in fastjsonschem * LRU: test * Removing snappy since it doesnt offer to Python3.11 * Adding support to Python3.11 in the layer for test * Skipping test * Skipping test for Python 3.11+ --------- Co-authored-by: Leandro Damascena <[email protected]>
1 parent ec62084 commit dfb9892

24 files changed

+406
-450
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ body:
6262
- "3.8"
6363
- "3.9"
6464
- "3.10"
65+
- "3.11"
6566
validations:
6667
required: true
6768
- type: dropdown

.github/ISSUE_TEMPLATE/static_typing.yml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ body:
2929
- "3.8"
3030
- "3.9"
3131
- "3.10"
32+
- "3.11"
3233
validations:
3334
required: true
3435
- type: input

.github/workflows/publish_v2_layer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
- name: Setup python
108108
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
109109
with:
110-
python-version: "3.10"
110+
python-version: "3.11"
111111
cache: "pip"
112112
- name: Resolve and install project dependencies
113113
# CDK spawns system python when compiling stack

.github/workflows/quality_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
strategy:
4545
max-parallel: 4
4646
matrix:
47-
python-version: ["3.7", "3.8", "3.9", "3.10"]
47+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
4848
env:
4949
PYTHON: "${{ matrix.python-version }}"
5050
permissions:

.github/workflows/quality_check_pydanticv2.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
strategy:
4545
max-parallel: 4
4646
matrix:
47-
python-version: ["3.7", "3.8", "3.9", "3.10"]
47+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
4848
env:
4949
PYTHON: "${{ matrix.python-version }}"
5050
permissions:

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
- name: Set up Python
134134
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
135135
with:
136-
python-version: "3.10"
136+
python-version: "3.11"
137137
cache: "poetry"
138138
- name: Install dependencies
139139
run: make dev
@@ -171,7 +171,7 @@ jobs:
171171
- name: Set up Python
172172
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
173173
with:
174-
python-version: "3.10"
174+
python-version: "3.11"
175175
cache: "poetry"
176176

177177
- name: Build python package and wheel

.github/workflows/reusable_deploy_v2_layer_stack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jobs:
160160
- name: Setup python
161161
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
162162
with:
163-
python-version: "3.10"
163+
python-version: "3.11"
164164
cache: "pip"
165165
- name: Resolve and install project dependencies
166166
# CDK spawns system python when compiling stack

.github/workflows/reusable_publish_docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- name: Set up Python
5353
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
5454
with:
55-
python-version: "3.10"
55+
python-version: "3.11"
5656
cache: "poetry"
5757
- name: Install dependencies
5858
run: make dev

.github/workflows/run-e2e-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
strategy:
4848
fail-fast: false # needed so if a version fails, the others will still be able to complete and cleanup
4949
matrix:
50-
version: ["3.7", "3.8", "3.9", "3.10"]
50+
version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
5151
if: ${{ github.actor != 'dependabot[bot]' }}
5252
steps:
5353
- name: "Checkout"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[![Build](https://github.com/aws-powertools/powertools-lambda-python/actions/workflows/quality_check.yml/badge.svg)](https://github.com/aws-powertools/powertools-lambda-python/actions/workflows/python_build.yml)
55
[![codecov.io](https://codecov.io/github/aws-powertools/powertools-lambda-python/branch/develop/graphs/badge.svg)](https://app.codecov.io/gh/aws-powertools/powertools-lambda-python)
6-
![PythonSupport](https://img.shields.io/static/v1?label=python&message=%203.7|%203.8|%203.9|%203.10&color=blue?style=flat-square&logo=python) ![PyPI version](https://badge.fury.io/py/aws-lambda-powertools.svg) ![PyPi monthly downloads](https://img.shields.io/pypi/dm/aws-lambda-powertools) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/aws-powertools/powertools-lambda-python/badge)](https://api.securityscorecards.dev/projects/github.com/aws-powertools/powertools-lambda-python) [![Join our Discord](https://dcbadge.vercel.app/api/server/B8zZKbbyET)](https://discord.gg/B8zZKbbyET)
6+
![PythonSupport](https://img.shields.io/static/v1?label=python&message=%203.7|%203.8|%203.9|%203.10|%203.11&color=blue?style=flat-square&logo=python) ![PyPI version](https://badge.fury.io/py/aws-lambda-powertools.svg) ![PyPi monthly downloads](https://img.shields.io/pypi/dm/aws-lambda-powertools) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/aws-powertools/powertools-lambda-python/badge)](https://api.securityscorecards.dev/projects/github.com/aws-powertools/powertools-lambda-python) [![Join our Discord](https://dcbadge.vercel.app/api/server/B8zZKbbyET)](https://discord.gg/B8zZKbbyET)
77

88
Powertools for AWS Lambda (Python) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda/python/latest/#features).
99

docs/tutorial/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Let's clone our sample project before we add one feature at a time.
2020
Bootstrap directly via SAM CLI:
2121

2222
```shell
23-
sam init --app-template hello-world-powertools-python --name sam-app --package-type Zip --runtime python3.10 --no-tracing`
23+
sam init --app-template hello-world-powertools-python --name sam-app --package-type Zip --runtime python3.11 --no-tracing`
2424
```
2525

2626
```bash title="Use SAM CLI to initialize the sample project"
27-
sam init --runtime python3.10 --dependency-manager pip --app-template hello-world --name powertools-quickstart
27+
sam init --runtime python3.11 --dependency-manager pip --app-template hello-world --name powertools-quickstart
2828
```
2929

3030
### Project structure

docs/utilities/jmespath_functions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ This sample will decompress and decode base64 data from Cloudwatch Logs, then us
189189

190190
For special binary formats that you want to decode before applying JSON Schema validation, you can bring your own [JMESPath function](https://github.com/jmespath/jmespath.py#custom-functions){target="_blank"} and any additional option via `jmespath_options` param. To keep Powertools for AWS Lambda (Python) built-in functions, you can subclass from `PowertoolsFunctions`.
191191

192-
Here is an example of how to decompress messages using [snappy](https://github.com/andrix/python-snappy){target="_blank"}:
192+
Here is an example of how to decompress messages using [zlib](https://docs.python.org/3/library/zlib.html){target="_blank"}:
193193

194194
=== "powertools_custom_jmespath_function.py"
195195

docs/we_made_this.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ A collection of articles explaining in detail how Lambda Powertools helps with a
3737

3838
* [Serverless API Idempotency with AWS Lambda Powertools and CDK](https://www.ranthebuilder.cloud/post/serverless-api-idempotency-with-aws-lambda-powertools-and-cdk){:target="_blank"}
3939

40-
* [Effective Amazon SQS Batch Handling with Powertools for AWS Lambda (Python)(https://www.ranthebuilder.cloud/post/effective-amazon-sqs-batch-handling-with-aws-lambda-powertools){:target="_blank"}
40+
* [Effective Amazon SQS Batch Handling with Powertools for AWS Lambda (Python)](https://www.ranthebuilder.cloud/post/effective-amazon-sqs-batch-handling-with-aws-lambda-powertools){:target="_blank"}
4141

4242
### Making all your APIs idempotent
4343

examples/idempotency/templates/terraform.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "aws_dynamodb_table" "IdempotencyTable" {
2828
resource "aws_lambda_function" "IdempotencyFunction" {
2929
function_name = "IdempotencyFunction"
3030
role = aws_iam_role.IdempotencyFunctionRole.arn
31-
runtime = "python3.10"
31+
runtime = "python3.11"
3232
handler = "app.lambda_handler"
3333
filename = "lambda.zip"
3434

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
{
22
"Records": [
33
{
4-
"user": "integration-kafka",
4+
"application": "notification",
55
"datetime": "2022-01-01T00:00:00.000Z",
6-
"log": "/QGIMjAyMi8wNi8xNiAxNjoyNTowMCBbY3JpdF0gMzA1MTg5MCMNCPBEOiAqMSBjb25uZWN0KCkg\ndG8gMTI3LjAuMC4xOjUwMDAgZmFpbGVkICgxMzogUGVybWlzc2lvbiBkZW5pZWQpIHdoaWxlEUEI\naW5nAUJAdXBzdHJlYW0sIGNsaWVudDoZVKgsIHNlcnZlcjogXywgcmVxdWVzdDogIk9QVElPTlMg\nLyBIVFRQLzEuMSIsFUckOiAiaHR0cDovLzabABQvIiwgaG8FQDAxMjcuMC4wLjE6ODEi\n"
7-
},
8-
{
9-
"user": "integration-kafka",
10-
"datetime": "2022-01-01T00:00:01.000Z",
11-
"log": "tQHwnDEyNy4wLjAuMSAtIC0gWzE2L0p1bi8yMDIyOjE2OjMwOjE5ICswMTAwXSAiT1BUSU9OUyAv\nIEhUVFAvMS4xIiAyMDQgMCAiLSIgIk1vemlsbGEvNS4wIChYMTE7IExpbnV4IHg4Nl82NCkgQXBw\nbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEwMi4BmUwwIFNhZmFy\naS81MzcuMzYiICItIg==\n"
6+
"log": "eJxtUNFOwkAQ/JXN+dJq6e22tMD5ZHwQRYSEJpqQhtRy2AvlWq+tEr/eg6DExOzDJjM7M5tZsgCDgGPMKQaKRRAJRFjmRrUphBjRcIQXpy3gkiCvtJZ567jQVkDBwEc7JCK0sk2mSrkGh0IBc2l2qmlUpWEttZJrFz4LS/8YKP12cOjqpjUy23mQl0rqVpw9PWik+ZBGwMoDI9872ViazebJ/expARzGSTLn5BPzfm0sX7RtLTj/+xq3N0V11J+JITELnwHo2VlSzB86zQ+1CFtIiIJGcIWEmP4bDgH2AYH1GLBp9aXKMuORj+C8EF3Do9LdHvbDeBX3Xbip61I+y9eJankUDvwwBmcyTqaPHpRqK+FO5tvKhdvCVDvJCYPjYwiLbJMZdZKwQxZL02+NI3Vs"
127
}
138
]
149
}

examples/jmespath_functions/src/powertools_custom_jmespath_function.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
import binascii
3+
import zlib
34

4-
import snappy
55
from jmespath.exceptions import JMESPathTypeError
66
from jmespath.functions import signature
77

@@ -15,9 +15,9 @@ class CustomFunctions(PowertoolsFunctions):
1515
# only decode if value is a string
1616
# see supported data types: https://jmespath.org/specification.html#built-in-functions
1717
@signature({"types": ["string"]})
18-
def _func_decode_snappy_compression(self, payload: str):
18+
def _func_decode_zlib_compression(self, payload: str):
1919
decoded: bytes = base64.b64decode(payload)
20-
return snappy.uncompress(decoded)
20+
return zlib.decompress(decoded)
2121

2222

2323
custom_jmespath_options = {"custom_functions": CustomFunctions()}
@@ -30,15 +30,15 @@ def lambda_handler(event, context) -> dict:
3030
extract_data_from_envelope(
3131
data=event,
3232
# NOTE: Use the prefix `_func_` before the name of the function
33-
envelope="Records[*].decode_snappy_compression(log)",
33+
envelope="Records[*].decode_zlib_compression(log)",
3434
jmespath_options=custom_jmespath_options,
3535
),
3636
)
3737
return {"logs": logs, "message": "Extracted messages", "success": True}
3838
except JMESPathTypeError:
3939
return return_error_message("The envelope function must match a valid path.")
40-
except snappy.UncompressError:
41-
return return_error_message("Log must be a valid snappy compressed binary")
40+
except zlib.error:
41+
return return_error_message("Log must be a valid zlib compressed message")
4242
except binascii.Error:
4343
return return_error_message("Log must be a valid base64 encoded string")
4444

0 commit comments

Comments
 (0)