From fa792febf656016de3e84160011ca3a12bd7e6e8 Mon Sep 17 00:00:00 2001 From: razumeiko <2330426+razumeiko@users.noreply.github.com> Date: Fri, 27 Aug 2021 15:25:48 +0300 Subject: [PATCH 1/4] Added AWS Lambda Python 3.9 runtime support --- sentry_sdk/integrations/aws_lambda.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 533250efaa..21de488cec 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -297,10 +297,14 @@ def get_lambda_bootstrap(): if "bootstrap" in sys.modules: return sys.modules["bootstrap"] elif "__main__" in sys.modules: - if hasattr(sys.modules["__main__"], "bootstrap"): + module = sys.modules["__main__"] + if hasattr(module, "awslambdaricmain") and hasattr(module, "bootstrap"): + return module.awslambdaricmain.bootstrap + 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 + + return module else: return None From 0a49b4757d762c931342dce150be0c41fc7dc146 Mon Sep 17 00:00:00 2001 From: razumeiko <2330426+razumeiko@users.noreply.github.com> Date: Fri, 27 Aug 2021 20:44:23 +0300 Subject: [PATCH 2/4] Ignore mypy module check --- sentry_sdk/integrations/aws_lambda.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 21de488cec..31d51343eb 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -299,7 +299,7 @@ def get_lambda_bootstrap(): elif "__main__" in sys.modules: module = sys.modules["__main__"] if hasattr(module, "awslambdaricmain") and hasattr(module, "bootstrap"): - return module.awslambdaricmain.bootstrap + return module.awslambdaricmain.bootstrap # type: ignore elif hasattr(module, "bootstrap"): # awslambdaric python module in container builds return module.bootstrap # type: ignore From a8eba2d95c55ecf4d6a8f1e9337e9d7731a02a83 Mon Sep 17 00:00:00 2001 From: razumeiko <2330426+razumeiko@users.noreply.github.com> Date: Wed, 29 Sep 2021 23:37:10 +0300 Subject: [PATCH 3/4] Fixed check bug and added python3.9 runtime to tests --- sentry_sdk/integrations/aws_lambda.py | 2 +- tests/integrations/aws_lambda/test_aws.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 31d51343eb..baa850d730 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -298,7 +298,7 @@ def get_lambda_bootstrap(): return sys.modules["bootstrap"] elif "__main__" in sys.modules: module = sys.modules["__main__"] - if hasattr(module, "awslambdaricmain") and hasattr(module, "bootstrap"): + if hasattr(module, "awslambdaricmain") and hasattr(module.awslambdaricmain, "bootstrap"): return module.awslambdaricmain.bootstrap # type: ignore elif hasattr(module, "bootstrap"): # awslambdaric python module in container builds diff --git a/tests/integrations/aws_lambda/test_aws.py b/tests/integrations/aws_lambda/test_aws.py index 0f50753be7..32c5c7d9f1 100644 --- a/tests/integrations/aws_lambda/test_aws.py +++ b/tests/integrations/aws_lambda/test_aws.py @@ -7,7 +7,7 @@ export SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID=.. export SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY=... - export SENTRY_PYTHON_TEST_AWS_IAM_ROLE="arn:aws:iam::920901907255:role/service-role/lambda" + export SENTRY_PYTHON_TEST_AWS_IAM_ROLE="arn:aws:iam::926856021716:role/collections-sasha-us-west-2-lambdaRole" If you need to debug a new runtime, use this REPL to figure things out: @@ -105,7 +105,7 @@ 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 From 3de96deb6c8b7fd170a1d6dfb561fc11f0ae9795 Mon Sep 17 00:00:00 2001 From: razumeiko <2330426+razumeiko@users.noreply.github.com> Date: Wed, 29 Sep 2021 23:40:02 +0300 Subject: [PATCH 4/4] Revert comment --- tests/integrations/aws_lambda/test_aws.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/aws_lambda/test_aws.py b/tests/integrations/aws_lambda/test_aws.py index 32c5c7d9f1..32000570cf 100644 --- a/tests/integrations/aws_lambda/test_aws.py +++ b/tests/integrations/aws_lambda/test_aws.py @@ -7,7 +7,7 @@ export SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID=.. export SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY=... - export SENTRY_PYTHON_TEST_AWS_IAM_ROLE="arn:aws:iam::926856021716:role/collections-sasha-us-west-2-lambdaRole" + export SENTRY_PYTHON_TEST_AWS_IAM_ROLE="arn:aws:iam::920901907255:role/service-role/lambda" If you need to debug a new runtime, use this REPL to figure things out: