Skip to content

Commit

Permalink
Added AWS Lambda Python 3.9 runtime support
Browse files Browse the repository at this point in the history
  • Loading branch information
razumeiko authored and Tom Shortall committed Nov 16, 2021
1 parent 5d357d0 commit 34378a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ targets:
- python3.6
- python3.7
- python3.8
- python3.9
license: MIT
changelog: CHANGELOG.md
changelogPolicy: simple
18 changes: 14 additions & 4 deletions sentry_sdk/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,33 @@ def get_lambda_bootstrap():
# Python 3.7: If the bootstrap module is *already imported*, it is the
# one we actually want to use (no idea what's in __main__)
#
# On Python 3.8 bootstrap is also importable, but will be the same file
# Python 3.8: bootstrap is also importable, but will be the same file
# as __main__ imported under a different name:
#
# sys.modules['__main__'].__file__ == sys.modules['bootstrap'].__file__
# sys.modules['__main__'] is not sys.modules['bootstrap']
#
# Python 3.9: bootstrap is in __main__.awslambdaricmain
#
# On container builds using the `aws-lambda-python-runtime-interface-client`
# (awslamdaric) module, bootstrap is located in sys.modules['__main__'].bootstrap
#
# Such a setup would then make all monkeypatches useless.
if "bootstrap" in sys.modules:
return sys.modules["bootstrap"]
elif "__main__" in sys.modules:
if hasattr(sys.modules["__main__"], "bootstrap"):
module = sys.modules["__main__"]
# python3.9 runtime
if hasattr(module, "awslambdaricmain") and hasattr(
module.awslambdaricmain, "bootstrap" # type: ignore
):
return module.awslambdaricmain.bootstrap # type: ignore
elif hasattr(module, "bootstrap"):
# awslambdaric python module in container builds
return sys.modules["__main__"].bootstrap # type: ignore
return sys.modules["__main__"]
return module.bootstrap # type: ignore

# python3.8 runtime
return module
else:
return None

Expand Down
4 changes: 3 additions & 1 deletion tests/integrations/aws_lambda/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def lambda_client():
return get_boto_client()


@pytest.fixture(params=["python3.6", "python3.7", "python3.8", "python2.7"])
@pytest.fixture(
params=["python3.6", "python3.7", "python3.8", "python3.9", "python2.7"]
)
def lambda_runtime(request):
return request.param

Expand Down

0 comments on commit 34378a1

Please sign in to comment.