Skip to content

Conversation

@florentinl
Copy link
Contributor

@florentinl florentinl commented Jul 2, 2025

Motivation

In the context of my internship, I am implementing Appsec for AWS Lambda through the python tracer to replace the current implementation which relies on the extension (the agent in the context of lambda).

The goal of this pull request is to be able to do end-to-end testing of the python tracer in the context of AWS Lambda.
To avoid relying on provisioning resources in AWS, I am attempting to emulate the AWS Lambda behaviour using a system-test Docker scenario.

A typical AWS Serverless deployment works with an AWS Managed Load Balancer such as APIGateway, ALB, or the Lambda Function Url service, the load balancer converts the incoming HTTP request to a json representation called an Event that is passed to the AWS Lambda runtime to execute the function.

graph LR
    A[Incoming HTTP Request] -->|HTTP| B[AWS Managed Load Balancer]
    B -->|event: request as JSON| C[AWS Lambda]
Loading

AWS Provides the AWS Lambda Runtime Interface Emulator to simulate the Lambda runtime inside a Docker container and a cli to emulate a local APIGateway (AWS SAM cli).

Leveraging these two tools, we can envision a DockerScenario with the following architecture:

graph LR
    A[Incoming HTTP Request] -->|HTTP| B[LambdaProxy]
    B -->|event: request as JSON| C[LambdaWeblog]
Loading

With the following components:

  • LambdaWeblog: A weblog app written as a lambda function, running with the AWS Lambda RIE
  • LambdaProxy: A small flask app, to convert http request to lambda events, invoke the function with this event and return the result as an http response. This one relies on primitives of AWS SAM cli, a tool to emulate an API Gateway locally

A specificity of this scenario is that the extension runs inside the LambdaWeblog because it needs access to the Lambda Runtime API, this requires the proxy to be able to send traces back to the weblog instead of sending them to a dedicated agent.

As a first step, this PR contains a single scenario to test Appsec capabilities for the APIGateway Rest API event type. The goal would be to eventually (in following PRs) emulate all other types of http events that a Lambda can receive: APIGateway HTTP API, Application Load Balancer, Lambda Function Url.

Changes

Additions:

  • A weblog for AWS Lambda python APIGateway Rest API with only a few routes for now
  • A helper container LambdaProxy to relay system-test http request to invoke the Lambda Runtime Interface
  • A new Scenario type LambdaScenario to orchestrate the two containers and configure the Proxy

Modifications:

  • Make the Proxy configurable so that it can send traces to the lambda extension instead of the dedicated agent container.
  • Add a new scenario of the new type LambdaScenario: appsec_lambda_deafult and add to it all appsec related tests of the default scenario

Workflow

  1. ⚠️ Create your PR as draft ⚠️
  2. Work on you PR until the CI passes
  3. Mark it as ready for review
    • Test logic is modified? -> Get a review from RFC owner.
    • Framework is modified, or non obvious usage of it -> get a review from R&P team

🚀 Once your PR is reviewed and the CI green, you can merge it!

🛟 #apm-shared-testing 🛟

Reviewer checklist

  • If PR title starts with [<language>], double-check that only <language> is impacted by the change
  • No system-tests internal is modified. Otherwise, I have the approval from R&P team
  • A docker base image is modified?
    • the relevant build-XXX-image label is present
  • A scenario is added (or removed)?

@florentinl florentinl force-pushed the florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway branch 10 times, most recently from 60a9891 to 37ead8a Compare July 4, 2025 07:57
@florentinl florentinl force-pushed the florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway branch 4 times, most recently from a556702 to 1c39ec9 Compare July 4, 2025 08:16
@florentinl florentinl changed the title Add scenario for testing the python tracer in an emulated AWS Lambda context [python_lambda] Add scenario for testing the python tracer for AWS Lambda Jul 4, 2025
@florentinl florentinl force-pushed the florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway branch 14 times, most recently from d00a7a0 to 7053105 Compare July 4, 2025 14:40
@florentinl florentinl force-pushed the florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway branch from 7ab8293 to 90f59e3 Compare August 5, 2025 11:16
@florentinl florentinl force-pushed the florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway branch 2 times, most recently from b0f990a to b23b513 Compare August 13, 2025 14:05
@florentinl florentinl force-pushed the florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway branch 4 times, most recently from 6e1e64a to 9546648 Compare August 20, 2025 08:46
@florentinl florentinl changed the title Add scenario for testing the python tracer for AWS Lambda [python_lambda] Add scenario for testing the python tracer for AWS Lambda Aug 20, 2025
@florentinl florentinl force-pushed the florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway branch from 9546648 to 219f30f Compare August 20, 2025 12:10
@florentinl florentinl merged commit 7496be4 into main Aug 20, 2025
616 checks passed
@florentinl florentinl deleted the florentin.labelle/APPSEC-58014/scenario-for-lambda-python-api-gateway branch August 20, 2025 13:39
scenario_groups=[scenario_groups.appsec],
)
appsec_lambda_api_security = LambdaScenario(
"APPSEC_LAMBDA_API_SECURITY",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario is not in the CI, so it's not tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants