Skip to content

Commit d742102

Browse files
committed
cleanup
1 parent 4d206a8 commit d742102

File tree

3 files changed

+28
-110
lines changed

3 files changed

+28
-110
lines changed

tests/integrations/aws_lambda/client.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

tests/integrations/aws_lambda/test_aws_lambda.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import boto3
22
import docker
33
import json
4-
import os
5-
import platform
64
import pytest
7-
import socket
85
import subprocess
96
import tempfile
107
import time
@@ -21,24 +18,6 @@
2118
SAM_TEMPLATE_FILE = "sam.template.yaml"
2219

2320

24-
def _get_host_ip():
25-
if os.environ.get("GITHUB_ACTIONS"):
26-
# Running in GitHub Actions
27-
hostname = socket.gethostname()
28-
host = socket.gethostbyname(hostname)
29-
else:
30-
# Running locally
31-
if platform.system() in ["Darwin", "Windows"]:
32-
# Windows or MacOS
33-
host = "host.docker.internal"
34-
else:
35-
# Linux
36-
hostname = socket.gethostname()
37-
host = socket.gethostbyname(hostname)
38-
39-
return host
40-
41-
4221
@pytest.fixture(scope="session", autouse=True)
4322
def test_environment():
4423
print("[test_environment fixture] Setting up AWS Lambda test infrastructure")
@@ -55,7 +34,7 @@ def test_environment():
5534

5635
# Create local AWS SAM stack
5736
app = App()
58-
stack = LocalLambdaStack(app, "LocalLambdaStack", host=_get_host_ip())
37+
stack = LocalLambdaStack(app, "LocalLambdaStack")
5938

6039
# Write SAM template to file
6140
template = app.synth().get_stack_by_name("LocalLambdaStack").template

tests/integrations/aws_lambda/utils.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import sys
66
import time
77
import threading
8+
import socket
9+
import platform
810

911
from aws_cdk import (
1012
CfnResource,
@@ -24,19 +26,35 @@
2426
PYTHON_VERSION = f"python{sys.version_info.major}.{sys.version_info.minor}"
2527

2628

29+
def get_host_ip():
30+
"""
31+
Returns the IP address of the host we are running on.
32+
"""
33+
if os.environ.get("GITHUB_ACTIONS"):
34+
# Running in GitHub Actions
35+
hostname = socket.gethostname()
36+
host = socket.gethostbyname(hostname)
37+
else:
38+
# Running locally
39+
if platform.system() in ["Darwin", "Windows"]:
40+
# Windows or MacOS
41+
host = "host.docker.internal"
42+
else:
43+
# Linux
44+
hostname = socket.gethostname()
45+
host = socket.gethostbyname(hostname)
46+
47+
return host
48+
49+
2750
class LocalLambdaStack(Stack):
2851
"""
2952
Uses the AWS CDK to create a local SAM stack containing Lambda functions.
3053
"""
3154

3255
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
33-
host = kwargs.pop("host", "host-not-specified")
34-
dsn = f"http://123@{host}:9999/0" # noqa: E231
35-
56+
print("[LocalLambdaStack] Creating local SAM Lambda Stack")
3657
super().__init__(scope, construct_id, **kwargs)
37-
print(
38-
"[LocalLambdaStack] Creating local SAM Lambda Stack (Sentry DSN: %s)" % dsn
39-
)
4058

4159
# Override the template synthesis
4260
self.template_options.template_format_version = "2010-09-09"
@@ -64,6 +82,9 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
6482
},
6583
)
6684

85+
dsn = f"http://123@{get_host_ip()}:9999/0" # noqa: E231
86+
print("[LocalLambdaStack] Using Sentry DSN: %s" % dsn)
87+
6788
print(
6889
"[LocalLambdaStack] Add all Lambda functions defined in "
6990
"/tests/integrations/aws_lambda/lambda_functions/ to the SAM stack"

0 commit comments

Comments
 (0)