Draft
Conversation
…upport Add ALBApiAttribute class that allows users to configure Lambda functions as targets behind an existing Application Load Balancer. The attribute supports: - Literal ARN or @ResourceName template references for the ALB listener - Path pattern conditions with wildcard support - Priority for listener rules (1-50000) - Optional multi-value headers, host header, and HTTP method conditions - Custom CloudFormation resource naming - Built-in validation for all properties Includes 37 unit tests covering construction, defaults, property tracking, and comprehensive validation scenarios.
Wire the ALBApiAttribute into the source generator's model infrastructure: - TypeFullNames: Add ALB request/response/attribute constants and ALBRequests set - EventType: Add ALB enum value - EventTypeBuilder: Detect ALBApiAttribute on methods - ALBApiAttributeBuilder: Parse ALBApiAttribute from Roslyn AttributeData - AttributeModelBuilder: Build AttributeModel<ALBApiAttribute> instances - LambdaMethodModel: Add ReturnsApplicationLoadBalancerResponse helper property - SyntaxReceiver: Register ALBApiAttribute as secondary attribute All 265 existing tests pass. 10 new model-layer unit tests added.
- GeneratedMethodModelBuilder: Handle ALB response type - when the method has [ALBApi], the generated wrapper returns ApplicationLoadBalancerResponse. If the user already returns ApplicationLoadBalancerResponse directly, the type is passed through unchanged. - LambdaFunctionValidator: Add dependency check for Amazon.Lambda.ApplicationLoadBalancerEvents when [ALBApi] is detected. ALB functions use the pass-through (NoEventMethodBody) path in the T4 templates, same as SQS - the user works directly with ApplicationLoadBalancerRequest/Response objects. All 265 tests pass.
Add ProcessAlbApiAttribute to CloudFormationWriter that generates three standalone CloudFormation resources for ALB Lambda integration: 1. AWS::Lambda::Permission - allows ELB to invoke the Lambda function 2. AWS::ElasticLoadBalancingV2::TargetGroup - registers Lambda as target with configurable multi-value headers support 3. AWS::ElasticLoadBalancingV2::ListenerRule - routes traffic based on path-pattern, optional host-header and HTTP method conditions Supports both literal ARN and @ResourceName template references for the ALB listener (using Ref for template references). All 265 existing tests pass.
Add 12 tests (6 scenarios x JSON/YAML) covering: - Basic ALB attribute generates TargetGroup, ListenerRule, and Permission - Template reference (@ResourceName) uses Ref for ListenerArn - MultiValueHeaders flag sets MultiValueHeadersEnabled on TargetGroup - Custom ResourceName uses custom prefix for all 3 resources - HostHeader condition adds host-header to ListenerRule conditions - HttpMethod condition adds http-request-method to ListenerRule conditions All 277 tests pass (265 original + 12 new).
Add end-to-end source generator test that verifies the full compilation pipeline for ALB-annotated Lambda functions: - ValidALBEvents.cs.txt: Test source with two ALB functions (literal ARN and @template reference with all optional properties) - Snapshot .g.cs files: Expected generated wrapper code for Hello and HandleRequest methods - albEvents.template: Expected CloudFormation template with TargetGroup, ListenerRule, Permission resources for both functions - CSharpSourceGeneratorVerifier: Added ApplicationLoadBalancerEvents assembly reference so the Roslyn test compilation can resolve ALB types All 278 tests pass (277 previous + 1 new snapshot test).
Add separate integration test project for ALB Lambda annotations: TestServerlessApp.ALB/: - ALBFunctions.cs: Two Lambda functions with [ALBApi] annotations (Hello at /hello priority 1, Health at /health priority 2) - serverless.template: VPC/ALB infrastructure (VPC, 2 subnets, Internet Gateway, route table, security group, ALB, HTTP listener with 404 default action). Source generator adds Lambda/ALB wiring. - aws-lambda-tools-defaults.json: Deployment configuration TestServerlessApp.ALB.IntegrationTests/: - ALBIntegrationTestContextFixture: Deploys stack, gets ALB DNS, waits for targets healthy, cleans up on dispose - ALBTargetTests: 4 tests verifying HTTP invocation via ALB (/hello returns 200+body, /health returns healthy, /unknown returns 404, target groups exist) - DeploymentScript.ps1: Creates S3 bucket, deploys via dotnet lambda Both projects build successfully. Integration tests require AWS credentials and deploy real infrastructure (~5 min).
Add TestServerlessApp.ALB and TestServerlessApp.ALB.IntegrationTests to Libraries.sln and Amazon.Lambda.Annotations.slnf. Also add Amazon.Lambda.ApplicationLoadBalancerEvents to the solution filter.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.