|
5 | 5 | import sys |
6 | 6 | import time |
7 | 7 | import threading |
| 8 | +import socket |
| 9 | +import platform |
8 | 10 |
|
9 | 11 | from aws_cdk import ( |
10 | 12 | CfnResource, |
|
24 | 26 | PYTHON_VERSION = f"python{sys.version_info.major}.{sys.version_info.minor}" |
25 | 27 |
|
26 | 28 |
|
| 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 | + |
27 | 50 | class LocalLambdaStack(Stack): |
28 | 51 | """ |
29 | 52 | Uses the AWS CDK to create a local SAM stack containing Lambda functions. |
30 | 53 | """ |
31 | 54 |
|
32 | 55 | 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") |
36 | 57 | super().__init__(scope, construct_id, **kwargs) |
37 | | - print( |
38 | | - "[LocalLambdaStack] Creating local SAM Lambda Stack (Sentry DSN: %s)" % dsn |
39 | | - ) |
40 | 58 |
|
41 | 59 | # Override the template synthesis |
42 | 60 | self.template_options.template_format_version = "2010-09-09" |
@@ -64,6 +82,9 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: |
64 | 82 | }, |
65 | 83 | ) |
66 | 84 |
|
| 85 | + dsn = f"http://123@{get_host_ip()}:9999/0" # noqa: E231 |
| 86 | + print("[LocalLambdaStack] Using Sentry DSN: %s" % dsn) |
| 87 | + |
67 | 88 | print( |
68 | 89 | "[LocalLambdaStack] Add all Lambda functions defined in " |
69 | 90 | "/tests/integrations/aws_lambda/lambda_functions/ to the SAM stack" |
|
0 commit comments