Skip to content

Commit f670a1b

Browse files
authored
test(aws_lambda): Add ARM64 architecture support for local Lambda testing (#7053)
Configure SAM Lambda functions to match the host CPU architecture, preventing slow x86_64 emulation on ARM machines like macOS. Also removes test_timeout_error which is a subset of test_timeout_error_scope_modified, reducing test run time. Refs PY-2641
1 parent 06f3264 commit f670a1b

2 files changed

Lines changed: 6 additions & 21 deletions

File tree

tests/integrations/aws_lambda/test_aws_lambda.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -201,27 +201,6 @@ def test_init_error(lambda_client, test_environment):
201201
assert transaction_event["transaction"] == "InitError"
202202

203203

204-
def test_timeout_error(lambda_client, test_environment):
205-
lambda_client.invoke(
206-
FunctionName="TimeoutError",
207-
Payload=json.dumps({}),
208-
)
209-
envelopes = test_environment["server"].envelopes
210-
211-
(error_event,) = envelopes
212-
213-
assert error_event["level"] == "error"
214-
assert error_event["extra"]["lambda"]["function_name"] == "TimeoutError"
215-
216-
(exception,) = error_event["exception"]["values"]
217-
assert not exception["mechanism"]["handled"]
218-
assert exception["type"] == "ServerlessTimeoutWarning"
219-
assert exception["value"].startswith(
220-
"WARNING : Function is expected to get timed out. Configured timeout duration ="
221-
)
222-
assert exception["mechanism"]["type"] == "threading"
223-
224-
225204
def test_timeout_error_scope_modified(lambda_client, test_environment):
226205
lambda_client.invoke(
227206
FunctionName="TimeoutErrorScopeModified",

tests/integrations/aws_lambda/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
PYTHON_VERSION = f"python{sys.version_info.major}.{sys.version_info.minor}"
3131

32+
# Match the host CPU architecture so local runs on ARM machines (e.g. macOS)
33+
# don't run the Lambda containers under slow x86_64 emulation.
34+
ARCHITECTURE = "arm64" if platform.machine() in ("arm64", "aarch64") else "x86_64"
35+
3236

3337
def get_host_ip():
3438
"""
@@ -105,6 +109,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
105109
"CodeUri": os.path.join(LAMBDA_FUNCTION_DIR, lambda_dir),
106110
"Handler": "sentry_sdk.integrations.init_serverless_sdk.sentry_lambda_handler",
107111
"Runtime": PYTHON_VERSION,
112+
"Architectures": [ARCHITECTURE],
108113
"Timeout": LAMBDA_FUNCTION_TIMEOUT,
109114
"Layers": [
110115
{"Ref": self.sentry_layer.logical_id}
@@ -172,6 +177,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
172177
"Handler": "index.handler",
173178
"Runtime": PYTHON_VERSION,
174179
"Timeout": LAMBDA_FUNCTION_TIMEOUT,
180+
"Architectures": [ARCHITECTURE],
175181
"Environment": {
176182
"Variables": {
177183
"SENTRY_DSN": dsn,

0 commit comments

Comments
 (0)