Skip to content

feat(general): add support for Python 3.11 #2820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ body:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
validations:
required: true
- type: dropdown
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/static_typing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ body:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
validations:
required: true
- type: input
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_v2_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: "3.10"
python-version: "3.11"
cache: "pip"
- name: Resolve and install project dependencies
# CDK spawns system python when compiling stack
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/quality_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
env:
PYTHON: "${{ matrix.python-version }}"
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/quality_check_pydanticv2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
env:
PYTHON: "${{ matrix.python-version }}"
permissions:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: "3.10"
python-version: "3.11"
cache: "poetry"
- name: Install dependencies
run: make dev
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: "3.10"
python-version: "3.11"
cache: "poetry"

- name: Build python package and wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_deploy_v2_layer_stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: "3.10"
python-version: "3.11"
cache: "pip"
- name: Resolve and install project dependencies
# CDK spawns system python when compiling stack
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: "3.10"
python-version: "3.11"
cache: "poetry"
- name: Install dependencies
run: make dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
strategy:
fail-fast: false # needed so if a version fails, the others will still be able to complete and cleanup
matrix:
version: ["3.7", "3.8", "3.9", "3.10"]
version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- name: "Checkout"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![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)
[![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)
![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)
![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)

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).

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Let's clone our sample project before we add one feature at a time.
Bootstrap directly via SAM CLI:

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

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

### Project structure
Expand Down
2 changes: 1 addition & 1 deletion docs/utilities/jmespath_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ This sample will decompress and decode base64 data from Cloudwatch Logs, then us

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`.

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

=== "powertools_custom_jmespath_function.py"

Expand Down
2 changes: 1 addition & 1 deletion docs/we_made_this.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ A collection of articles explaining in detail how Lambda Powertools helps with a

* [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"}

* [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"}
* [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"}

### Making all your APIs idempotent

Expand Down
2 changes: 1 addition & 1 deletion examples/idempotency/templates/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ resource "aws_dynamodb_table" "IdempotencyTable" {
resource "aws_lambda_function" "IdempotencyFunction" {
function_name = "IdempotencyFunction"
role = aws_iam_role.IdempotencyFunctionRole.arn
runtime = "python3.10"
runtime = "python3.11"
handler = "app.lambda_handler"
filename = "lambda.zip"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"Records": [
{
"user": "integration-kafka",
"application": "notification",
"datetime": "2022-01-01T00:00:00.000Z",
"log": "/QGIMjAyMi8wNi8xNiAxNjoyNTowMCBbY3JpdF0gMzA1MTg5MCMNCPBEOiAqMSBjb25uZWN0KCkg\ndG8gMTI3LjAuMC4xOjUwMDAgZmFpbGVkICgxMzogUGVybWlzc2lvbiBkZW5pZWQpIHdoaWxlEUEI\naW5nAUJAdXBzdHJlYW0sIGNsaWVudDoZVKgsIHNlcnZlcjogXywgcmVxdWVzdDogIk9QVElPTlMg\nLyBIVFRQLzEuMSIsFUckOiAiaHR0cDovLzabABQvIiwgaG8FQDAxMjcuMC4wLjE6ODEi\n"
},
{
"user": "integration-kafka",
"datetime": "2022-01-01T00:00:01.000Z",
"log": "tQHwnDEyNy4wLjAuMSAtIC0gWzE2L0p1bi8yMDIyOjE2OjMwOjE5ICswMTAwXSAiT1BUSU9OUyAv\nIEhUVFAvMS4xIiAyMDQgMCAiLSIgIk1vemlsbGEvNS4wIChYMTE7IExpbnV4IHg4Nl82NCkgQXBw\nbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEwMi4BmUwwIFNhZmFy\naS81MzcuMzYiICItIg==\n"
"log": "eJxtUNFOwkAQ/JXN+dJq6e22tMD5ZHwQRYSEJpqQhtRy2AvlWq+tEr/eg6DExOzDJjM7M5tZsgCDgGPMKQaKRRAJRFjmRrUphBjRcIQXpy3gkiCvtJZ567jQVkDBwEc7JCK0sk2mSrkGh0IBc2l2qmlUpWEttZJrFz4LS/8YKP12cOjqpjUy23mQl0rqVpw9PWik+ZBGwMoDI9872ViazebJ/expARzGSTLn5BPzfm0sX7RtLTj/+xq3N0V11J+JITELnwHo2VlSzB86zQ+1CFtIiIJGcIWEmP4bDgH2AYH1GLBp9aXKMuORj+C8EF3Do9LdHvbDeBX3Xbip61I+y9eJankUDvwwBmcyTqaPHpRqK+FO5tvKhdvCVDvJCYPjYwiLbJMZdZKwQxZL02+NI3Vs"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64
import binascii
import zlib

import snappy
from jmespath.exceptions import JMESPathTypeError
from jmespath.functions import signature

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


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

Expand Down
Loading