Skip to content

Commit 079135e

Browse files
brienseaStefan9283
andauthored
Add python3.13. (#175)
* Add python3.13. * Fix integ tests --------- Co-authored-by: Stefan Toma <[email protected]>
1 parent 2fe3eca commit 079135e

14 files changed

+253
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can include this package in your preferred base image to make that base imag
1010

1111
## Requirements
1212
The Python Runtime Interface Client package currently supports Python versions:
13-
- 3.7.x up to and including 3.12.x
13+
- 3.7.x up to and including 3.13.x
1414

1515
## Usage
1616

awslambdaric/bootstrap.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,10 @@ def run(app_root, handler, lambda_runtime_api_addr):
454454
sys.stdout = Unbuffered(sys.stdout)
455455
sys.stderr = Unbuffered(sys.stderr)
456456

457-
use_thread_for_polling_next = (
458-
os.environ.get("AWS_EXECUTION_ENV") == "AWS_Lambda_python3.12"
459-
)
457+
use_thread_for_polling_next = os.environ.get("AWS_EXECUTION_ENV") in [
458+
"AWS_Lambda_python3.12",
459+
"AWS_Lambda_python3.13",
460+
]
460461

461462
with create_log_sink() as log_sink:
462463
lambda_runtime_client = LambdaRuntimeClient(

awslambdaric/lambda_runtime_marshaller.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
# We also set 'ensure_ascii=False' so that the encoded json contains unicode characters instead of unicode escape sequences
1616
class Encoder(json.JSONEncoder):
1717
def __init__(self):
18-
if os.environ.get("AWS_EXECUTION_ENV") == "AWS_Lambda_python3.12":
18+
if os.environ.get("AWS_EXECUTION_ENV") in {
19+
"AWS_Lambda_python3.12",
20+
"AWS_Lambda_python3.13",
21+
}:
1922
super().__init__(use_decimal=False, ensure_ascii=False, allow_nan=True)
2023
else:
2124
super().__init__(use_decimal=False, allow_nan=True)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def read_requirements(req="base.txt"):
9191
"Programming Language :: Python :: 3.10",
9292
"Programming Language :: Python :: 3.11",
9393
"Programming Language :: Python :: 3.12",
94+
"Programming Language :: Python :: 3.13",
9495
"License :: OSI Approved :: Apache Software License",
9596
"Operating System :: OS Independent",
9697
],

tests/integration/codebuild/buildspec.os.alpine.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ batch:
2222
- "3.10"
2323
- "3.11"
2424
- "3.12"
25+
- "3.13"
2526
phases:
2627
pre_build:
2728
commands:

tests/integration/codebuild/buildspec.os.amazonlinux.2.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 0.2
22

33
env:
44
variables:
5-
OS_DISTRIBUTION: amazonlinux
5+
OS_DISTRIBUTION: amazonlinux2
66
PYTHON_LOCATION: "/usr/local/bin/python3"
77
TEST_NAME: "aws-lambda-python-rtc-amazonlinux-test"
88
batch:
@@ -20,7 +20,6 @@ batch:
2020
- "3.9"
2121
- "3.10"
2222
- "3.11"
23-
- "3.12"
2423
phases:
2524
pre_build:
2625
commands:
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
version: 0.2
2+
3+
env:
4+
variables:
5+
OS_DISTRIBUTION: amazonlinux2023
6+
PYTHON_LOCATION: "/usr/local/bin/python3"
7+
TEST_NAME: "aws-lambda-python-rtc-amazonlinux-test"
8+
batch:
9+
build-matrix:
10+
static:
11+
ignore-failure: false
12+
env:
13+
privileged-mode: true
14+
dynamic:
15+
env:
16+
variables:
17+
DISTRO_VERSION:
18+
- "2023"
19+
RUNTIME_VERSION:
20+
- "3.12"
21+
- "3.13"
22+
phases:
23+
pre_build:
24+
commands:
25+
- export IMAGE_TAG="python-${OS_DISTRIBUTION}-${DISTRO_VERSION}:${RUNTIME_VERSION}"
26+
- echo "Extracting and including the Runtime Interface Emulator"
27+
- SCRATCH_DIR=".scratch"
28+
- mkdir "${SCRATCH_DIR}"
29+
- ARCHITECTURE=$(arch)
30+
- >
31+
if [[ "$ARCHITECTURE" == "x86_64" ]]; then
32+
RIE="aws-lambda-rie"
33+
elif [[ "$ARCHITECTURE" == "aarch64" ]]; then
34+
RIE="aws-lambda-rie-arm64"
35+
else
36+
echo "Architecture $ARCHITECTURE is not currently supported."
37+
exit 1
38+
fi
39+
- tar -xvf tests/integration/resources/${RIE}.tar.gz --directory "${SCRATCH_DIR}"
40+
- >
41+
cp "tests/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}" \
42+
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
43+
- >
44+
echo "COPY ${SCRATCH_DIR}/${RIE} /usr/bin/${RIE}" >> \
45+
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
46+
- >
47+
echo '{"registry-mirrors": ["https://mirror.gcr.io"]}' > /etc/docker/daemon.json
48+
service docker restart
49+
- echo "Building image ${IMAGE_TAG}"
50+
- >
51+
docker build . \
52+
-f "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" \
53+
-t "${IMAGE_TAG}" \
54+
--build-arg RUNTIME_VERSION="${RUNTIME_VERSION}" \
55+
--build-arg DISTRO_VERSION="${DISTRO_VERSION}" \
56+
--build-arg ARCHITECTURE="${ARCHITECTURE}" \
57+
--load
58+
build:
59+
commands:
60+
- set -x
61+
- echo "Running Image ${IMAGE_TAG}"
62+
- docker network create "${TEST_NAME}-network"
63+
- >
64+
docker run \
65+
--detach \
66+
--name "${TEST_NAME}-app" \
67+
--network "${TEST_NAME}-network" \
68+
--entrypoint="" \
69+
"${IMAGE_TAG}" \
70+
sh -c "/usr/bin/${RIE} ${PYTHON_LOCATION} -m awslambdaric app.handler"
71+
- sleep 2
72+
- >
73+
docker run \
74+
--name "${TEST_NAME}-tester" \
75+
--env "TARGET=${TEST_NAME}-app" \
76+
--network "${TEST_NAME}-network" \
77+
--entrypoint="" \
78+
"${IMAGE_TAG}" \
79+
sh -c 'curl -X POST "http://${TARGET}:8080/2015-03-31/functions/function/invocations" -d "{}" --max-time 10'
80+
- actual="$(docker logs --tail 1 "${TEST_NAME}-tester" | xargs)"
81+
- expected='success'
82+
- |
83+
echo "Response: ${actual}"
84+
if [[ "$actual" != "$expected" ]]; then
85+
echo "fail! runtime: $RUNTIME - expected output $expected - got $actual"
86+
exit -1
87+
fi
88+
finally:
89+
- |
90+
echo "---------Container Logs: ${TEST_NAME}-app----------"
91+
echo
92+
docker logs "${TEST_NAME}-app" || true
93+
echo
94+
echo "---------------------------------------------------"
95+
echo "--------Container Logs: ${TEST_NAME}-tester--------"
96+
echo
97+
docker logs "${TEST_NAME}-tester" || true
98+
echo
99+
echo "---------------------------------------------------"
100+
- echo "Cleaning up..."
101+
- docker stop "${TEST_NAME}-app" || true
102+
- docker rm --force "${TEST_NAME}-app" || true
103+
- docker stop "${TEST_NAME}-tester" || true
104+
- docker rm --force "${TEST_NAME}-tester" || true
105+
- docker network rm "${TEST_NAME}-network" || true

tests/integration/codebuild/buildspec.os.debian.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ batch:
2222
- "3.10"
2323
- "3.11"
2424
- "3.12"
25+
- "3.13"
2526
phases:
2627
pre_build:
2728
commands:

tests/integration/codebuild/buildspec.os.ubuntu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ batch:
2222
- "3.10"
2323
- "3.11"
2424
- "3.12"
25+
- "3.13"
2526
phases:
2627
pre_build:
2728
commands:

tests/integration/docker/Dockerfile.echo.alpine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ RUN mkdir -p ${RIC_BUILD_DIR}
3131
# Copy function code and Runtime Interface Client .tgz
3232
WORKDIR ${RIC_BUILD_DIR}
3333
COPY . .
34+
RUN pip3 install setuptools
3435
RUN make init build test && \
3536
mv ./dist/awslambdaric-*.tar.gz ./dist/awslambdaric-test.tar.gz
3637

0 commit comments

Comments
 (0)