Skip to content

Commit b286406

Browse files
feat(aws): AWS Lambda Python 3.9 runtime support (#1239)
- Added AWS Lambda Python 3.9 runtime support - Fixed check bug and added python3.9 runtime to tests - add python3.9 as compatible runtime in .craft.yml Co-authored-by: razumeiko <[email protected]>
1 parent 5d357d0 commit b286406

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

.craft.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ targets:
2121
- python3.6
2222
- python3.7
2323
- python3.8
24+
- python3.9
2425
license: MIT
2526
changelog: CHANGELOG.md
2627
changelogPolicy: simple

sentry_sdk/integrations/aws_lambda.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,23 +284,33 @@ def get_lambda_bootstrap():
284284
# Python 3.7: If the bootstrap module is *already imported*, it is the
285285
# one we actually want to use (no idea what's in __main__)
286286
#
287-
# On Python 3.8 bootstrap is also importable, but will be the same file
287+
# Python 3.8: bootstrap is also importable, but will be the same file
288288
# as __main__ imported under a different name:
289289
#
290290
# sys.modules['__main__'].__file__ == sys.modules['bootstrap'].__file__
291291
# sys.modules['__main__'] is not sys.modules['bootstrap']
292292
#
293+
# Python 3.9: bootstrap is in __main__.awslambdaricmain
294+
#
293295
# On container builds using the `aws-lambda-python-runtime-interface-client`
294296
# (awslamdaric) module, bootstrap is located in sys.modules['__main__'].bootstrap
295297
#
296298
# Such a setup would then make all monkeypatches useless.
297299
if "bootstrap" in sys.modules:
298300
return sys.modules["bootstrap"]
299301
elif "__main__" in sys.modules:
300-
if hasattr(sys.modules["__main__"], "bootstrap"):
302+
module = sys.modules["__main__"]
303+
# python3.9 runtime
304+
if hasattr(module, "awslambdaricmain") and hasattr(
305+
module.awslambdaricmain, "bootstrap" # type: ignore
306+
):
307+
return module.awslambdaricmain.bootstrap # type: ignore
308+
elif hasattr(module, "bootstrap"):
301309
# awslambdaric python module in container builds
302-
return sys.modules["__main__"].bootstrap # type: ignore
303-
return sys.modules["__main__"]
310+
return module.bootstrap # type: ignore
311+
312+
# python3.8 runtime
313+
return module
304314
else:
305315
return None
306316

tests/integrations/aws_lambda/test_aws.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def lambda_client():
105105
return get_boto_client()
106106

107107

108-
@pytest.fixture(params=["python3.6", "python3.7", "python3.8", "python2.7"])
108+
@pytest.fixture(
109+
params=["python3.6", "python3.7", "python3.8", "python3.9", "python2.7"]
110+
)
109111
def lambda_runtime(request):
110112
return request.param
111113

0 commit comments

Comments
 (0)