Skip to content

Several minor discrepancies between "cargo lambda watch" and actually running on aws #863

Description

@Jimmy-Z
  • when there's no query, payload.rawQueryString on watch is Null, on aws it's String("").
  • payload.requestContext.http.protocol on watch is http, on aws it's HTTP/1.1.
  • there's an extra payload.httpMethod member on watch, which is identical to payload.requestContext.http.method, doesn't exist on aws.
  • payload.requestContext.http.userAgent on watch is cargo-lambda, on aws it mirrors payload.headers.user-agent
  • there's an extra payload.headers.lambda-runtime-aws-request-id header on watch, which mirrors payload.requestContext.requestId, doesn't exist on aws.

code is adapted from the streaming example
local testing is cargo lambda watch then curl http://127.0.0.1:9000
aws testing is deploying it as a function url, then curl

use lambda_runtime::{
	Error, LambdaEvent, service_fn,
	streaming::{Body, Response},
	tracing,
};
use serde_json::Value;

async fn func(event: LambdaEvent<Value>) -> Result<Response<Body>, Error> {
	let diag = format!("{:#?}", event.payload);

	let mut resp = Response::from(Body::from(diag));
	resp.metadata_prelude.headers.append("content-type", "text/plain".parse().unwrap());

	Ok(resp)
}

#[tokio::main]
async fn main() -> Result<(), Error> {
	// required to enable CloudWatch error logging by the runtime
	tracing::init_default_subscriber();

	lambda_runtime::run(service_fn(func)).await?;
	Ok(())
}

Activity

  1. jlizen commented on Jun 30, 2025

    @jlizen
    Contributor

    These all seem like great improvements to me, @Jimmy-Z ! Were you planning on cutting a PR for them?

  2. calavera commented on Jun 30, 2025

    @calavera
    Collaborator

    This is probably because you're using Lambda Function URLs in production, while Cargo Lambda always sends ALB payloads. The easiest way to ignore these discrepancies is by using lambda-http instead of raw events. That will guarantee that the data is in the same places regardless of whether it's production or development.

    Use this example as a starting point: https://github.com/awslabs/aws-lambda-rust-runtime/blob/main/examples/http-basic-lambda/src/main.rs

  3. Jimmy-Z commented on Jun 30, 2025

    @Jimmy-Z
    Author

    @jlizen Thanks for the hospitality, but I'm afraid I'm too new to this to make a PR.

    @calavera I agree these are minor problems, and can be easily work around, but I think it's still worth noting, it might make newbie(me) wonder why their(my) program behaves differently, maybe something like "there are known minor differences in header handling when ..." somewhere in doc would be helpful enough.

  4. Jimmy-Z commented on Jun 30, 2025

    @Jimmy-Z
    Author

    I'm not sure if this is off-topic, as for why I'm using lambda-runtime instead of lambda-http, 1st I couldn't find a streaming example using lambda-http, 2nd is this: aws/aws-lambda-rust-runtime#632 (reply in thread)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions