Overview
Explore the feasibility of extracting payloads from various Lambda event types using decorator attributes. This approach would require handlers to be decorated with metadata about expected request and response types, enabling the framework to intelligently extract the relevant payload from different Lambda event structures.
Background
AWS Lambda functions can be triggered by various event sources (API Gateway, S3, SNS, SQS, EventBridge, etc.), each with different event structures. Currently, handlers need to know the specific event structure, but this feature would allow automatic payload extraction based on attribute metadata.
Research Objectives
1. Attribute Design
- Design attribute(s) to specify event type and payload extraction logic
- Determine what metadata is needed:
- Event type (e.g.,
ApiGatewayProxyRequest, S3Event, SQSEvent)
- Payload location within the event (e.g.,
Body, Records[].Body, etc.)
- Request/response type mappings
- Serialization/deserialization requirements
Example concept:
[LambdaEvent(EventType.ApiGatewayProxy, RequestType = typeof(MyRequest), ResponseType = typeof(MyResponse))]
public MyResponse Handle(MyRequest request) { }
// or more granular:
[ApiGatewayEvent]
[RequestType<MyRequest>]
[ResponseType<MyResponse>]
public MyResponse Handle(MyRequest request) { }
2. Event Type Coverage
Research common Lambda event sources and their payload structures:
- API Gateway:
APIGatewayProxyRequest → extract from Body property
- Application Load Balancer:
ApplicationLoadBalancerRequest → extract from Body
- S3:
S3Event → extract from Records[].S3.Object
- SQS:
SQSEvent → extract from Records[].Body
- SNS:
SNSEvent → extract from Records[].Sns.Message
- EventBridge:
EventBridgeEvent<T> → extract from Detail
- DynamoDB Streams:
DynamoDBEvent → extract from Records[]
- Kinesis:
KinesisEvent → extract from Records[].Data
3. Source Generator Integration
Investigate how to generate extraction logic:
- Generate type-safe extraction code based on attributes
- Handle deserialization (JSON → POCO)
- Error handling for malformed events
- Support for custom extraction logic
Example generated code concept:
// Generated handler wrapper
private static async Task<APIGatewayProxyResponse> GeneratedHandler(
APIGatewayProxyRequest lambdaEvent,
ILambdaContext context)
{
// Extract payload from event.Body
var request = JsonSerializer.Deserialize<MyRequest>(lambdaEvent.Body);
// Invoke user handler
var response = await userHandler.Handle(request);
// Wrap response
return new APIGatewayProxyResponse
{
StatusCode = 200,
Body = JsonSerializer.Serialize(response)
};
}
4. Error Handling and Validation
- What happens when event structure doesn't match expectations?
- How to provide meaningful diagnostics at compile-time?
- Runtime validation and error reporting
5. Performance Considerations
- Impact on cold start times
- Serialization/deserialization overhead
- AOT compatibility (ensure generated code is AOT-safe)
Research Tasks
Potential Challenges
1. Type Safety
- How to ensure event type matches attribute declaration at compile-time?
- Roslyn analysis to validate event parameter types?
2. Complexity
- Some events (S3, SQS, SNS) contain arrays of records - how to handle batching?
- Nested payload structures
- Multiple serialization formats (JSON, Base64, etc.)
3. Flexibility vs. Convention
- Balance between automatic "magic" and explicit control
- Need escape hatches for custom extraction logic
4. Diagnostics
Generator diagnostics needed:
- Mismatched event type and attribute
- Missing required metadata
- Incompatible request/response types
- Multiple event attributes on single handler
Success Criteria
Decision Points
After research, decide:
- Proceed or Defer? Is this feature worth the complexity?
- Scope: Which event types to support in v1?
- API Design: Final attribute syntax and semantics
- Opt-in or Default? Should this be an alternative approach or replace current patterns?
Related Issues
Priority
Research/Exploration - Not blocking other work, but informs future architectural decisions.
Estimated Effort
2-3 days for initial research and prototype
Note: This is a research story. The goal is exploration and documentation of findings, not necessarily a complete implementation. Findings will inform whether to proceed with a full implementation story.
Overview
Explore the feasibility of extracting payloads from various Lambda event types using decorator attributes. This approach would require handlers to be decorated with metadata about expected request and response types, enabling the framework to intelligently extract the relevant payload from different Lambda event structures.
Background
AWS Lambda functions can be triggered by various event sources (API Gateway, S3, SNS, SQS, EventBridge, etc.), each with different event structures. Currently, handlers need to know the specific event structure, but this feature would allow automatic payload extraction based on attribute metadata.
Research Objectives
1. Attribute Design
ApiGatewayProxyRequest,S3Event,SQSEvent)Body,Records[].Body, etc.)Example concept:
2. Event Type Coverage
Research common Lambda event sources and their payload structures:
APIGatewayProxyRequest→ extract fromBodypropertyApplicationLoadBalancerRequest→ extract fromBodyS3Event→ extract fromRecords[].S3.ObjectSQSEvent→ extract fromRecords[].BodySNSEvent→ extract fromRecords[].Sns.MessageEventBridgeEvent<T>→ extract fromDetailDynamoDBEvent→ extract fromRecords[]KinesisEvent→ extract fromRecords[].Data3. Source Generator Integration
Investigate how to generate extraction logic:
Example generated code concept:
4. Error Handling and Validation
5. Performance Considerations
Research Tasks
Potential Challenges
1. Type Safety
2. Complexity
3. Flexibility vs. Convention
4. Diagnostics
Generator diagnostics needed:
Success Criteria
Decision Points
After research, decide:
Related Issues
Priority
Research/Exploration - Not blocking other work, but informs future architectural decisions.
Estimated Effort
2-3 days for initial research and prototype
Note: This is a research story. The goal is exploration and documentation of findings, not necessarily a complete implementation. Findings will inform whether to proceed with a full implementation story.