extract_authorizer_context

Function extract_authorizer_context 

Source
pub fn extract_authorizer_context(req: &Request) -> HashMap<String, String>
Expand description

Extract authorizer context from Lambda request extensions

Supports both API Gateway V1 (REST API) and V2 (HTTP API) formats. Returns HashMap with snake_case keys ready for header injection.

§Behavior

  • Returns empty HashMap if no authorizer context present
  • Converts camelCase to snake_case (userId → user_id)
  • Skips fields that fail sanitization
  • Converts non-string values to JSON strings
  • Handles both ApiGatewayV2.authorizer.fields and ApiGateway.authorizer["lambda"]

§Examples

let fields = extract_authorizer_context(&request);
assert_eq!(fields.get("account_id"), Some(&"acc_123".to_string()));