-
Notifications
You must be signed in to change notification settings - Fork 14
[python_lambda] Add scenario for testing the python tracer for AWS Lambda #4891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
florentinl
merged 14 commits into
main
from
florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway
Aug 20, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b3a7c3f
Add helper container to translate http requests to API Gateway Events
florentinl 1cc7b63
[python] Add aws apigw-rest weblog container
florentinl d794866
Add scenario for running lambdas inside Docker
florentinl f319696
Add lambda-proxy to build image job
florentinl e455383
Move lambda weblog to a different library
florentinl e0b9a07
Add manifest for python_lambda
florentinl 9ee01f0
Fix build lambda layer issue
florentinl 00ccdf6
Easy fixes after review
florentinl c87c323
Add aws_lambda documentation
florentinl f9ce6fe
[python_lambda] fetch artifact from github action workflow
florentinl f20a5de
[python_lambda] simplify installation of datadog_lambda
florentinl b51825f
[python_lambda] update manifest
florentinl 9c2310d
[python_lambda] fix issues preventing some tests
florentinl 219f30f
fix minor tweaks
florentinl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Lambda Testing scenario | ||
|
|
||
| The Lambda scenario is a variation on the [classical architecture](../architecture/overview.md#what-are-the-components-of-a-running-test) of the system-tests tailored to evaluate the `AWS Lambda` variants of the tracers when used to serve HTTP requests. | ||
|
|
||
| To achieve this we simulate the following AWS deployment architecture inside the system-tests using AWS provided tools : | ||
|
|
||
| ```mermaid | ||
| graph LR | ||
| A[Incoming HTTP Request] -->|HTTP| B[AWS Managed Load Balancer] | ||
| B -->|event: request as JSON| C[AWS Lambda] | ||
| ``` | ||
|
|
||
| The AWS Managed Load Balancer could be any of the following ones: | ||
| - API Gateway | ||
| - Application Load Balancer | ||
| - Lambda function url service | ||
|
|
||
| To do this, we rely on two tools from AWS to emulate Lambda and Load Balancers: | ||
| - [AWS Lambda Runtime Interface Emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator) | ||
| - [AWS SAM cli](https://github.com/aws/aws-sam-cli) | ||
|
|
||
| >Note: for now only the python variant ([`datadog_lambda`](https://github.com/DataDog/datadog-lambda-python)) is being tested simulating an `API Gateway` | ||
|
|
||
| ## Key differences with end to end scenarios | ||
|
|
||
| To replace the **AWS Managed Load Balancer**, we run a dedicated container in front of the weblog named **Lambda Proxy**. It is responsible for converting the incoming request to a *lambda event* representation, invoking the lambda function running inside the weblog and converting back the return value of function to an http response. | ||
|
|
||
| The **Lambda Function** runs inside the **Weblog Container** thanks to the *AWS Lambda Runtime Interface Emumlator*. | ||
|
|
||
|
|
||
| There is no **Agent Container**, the **Datadog Extension** (equivalent to the **Datadog Agent** in the context of lambda) needs to run inside the **Weblog Container**, the [**Application Proxy Container**](../architecture/overview.md#application-proxy-container) therefore needs to send traces back to the **Weblog Container**. | ||
|
|
||
|
|
||
| ```mermaid | ||
| flowchart TD | ||
| TESTS[Tests Container] -->|Send Requests| LambdaProxy | ||
| LambdaProxy[Lambda Proxy] -->|Send Lambda Event| Application | ||
| subgraph APP[Application Container] | ||
| socat[socat *:8127] --> Extension | ||
| Extension[Extension localhost:8126] | ||
| Application[Application *:8080] | ||
| end | ||
| Application --> | Send Traces | APPPROXY | ||
| APPPROXY[Application Proxy] --> | Send back traces | socat | ||
| APPPROXY -->|mitmdump| TESTS | ||
| Extension --> AGENTPROXY | ||
| AGENTPROXY[Agent Proxy] -->|remote request| BACKEND | ||
| AGENTPROXY -->|mitmdump| TESTS | ||
| BACKEND[Datadog] -->|trace API| TESTS | ||
| ``` | ||
|
|
||
| ## Specific considerations for the weblogs | ||
|
|
||
| On top of responding to the regular [`/healthcheck`](../weblog/README.md#get-healthcheck) endpoint. | ||
|
|
||
| Lambda Weblogs should respond the same JSON dict response to the non HTTP event: | ||
| ```json | ||
| { | ||
| "healthcheck": true | ||
| } | ||
| ``` | ||
|
|
||
| This is because the healthcheck is sent by the Lambda Weblog container itself which has no knowledge of how to serialize it as the event type expected by the weblog. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| tests/: | ||
| appsec/: | ||
| test_alpha.py: | ||
| Test_Basic: 7.112.0 | ||
| test_only_python.py: | ||
| Test_ImportError: 7.112.0 | ||
| test_reports.py: | ||
| Test_ExtraTagsFromRule: 7.112.0 | ||
| Test_Info: 7.112.0 | ||
| Test_RequestHeaders: 7.112.0 | ||
| Test_StatusCode: 7.112.0 | ||
| test_traces.py: | ||
| Test_AppSecEventSpanTags: 7.112.0 | ||
| Test_AppSecObfuscator: 7.112.0 | ||
| Test_CollectDefaultRequestHeader: 7.112.0 | ||
| Test_CollectRespondHeaders: 7.112.0 | ||
| Test_ExternalWafRequestsIdentification: 7.112.0 | ||
| Test_RetainTraces: 7.112.0 | ||
| test_versions.py: | ||
| Test_Events: 7.112.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.