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.
…tes for ALB TargetGroup MultiValueHeadersEnabled is not a valid CloudFormation property on AWS::ElasticLoadBalancingV2::TargetGroup. Multi-value headers must be configured via TargetGroupAttributes with the key lambda.multi_value_headers.enabled. Changes: - CloudFormationWriter: emit TargetGroupAttributes array when MultiValueHeaders=true, remove it when false (instead of setting the non-existent MultiValueHeadersEnabled property) - albEvents.template snapshot: remove MultiValueHeadersEnabled=false, add TargetGroupAttributes for the multi-value-headers case - ALBEventsTests: update assertions to check TargetGroupAttributes existence instead of MultiValueHeadersEnabled - TestServerlessApp.ALB/serverless.template: remove stale MultiValueHeadersEnabled from both target groups
- Add 'Application Load Balancer (ALB) Example' section with: - Property reference table for ALBApi attribute - Method signature requirements - Prerequisites (existing ALB listener required) - Basic example with @ResourceName template reference - Literal listener ARN example - Advanced example with all optional properties - Generated CloudFormation resources walkthrough - Multi-value headers and condition examples - Minimal ALB infrastructure template snippet - Add ALBApi to Event Attributes reference list - Add Amazon.Lambda.ApplicationLoadBalancerEvents to Project References - Update table of contents
The CloudFormation property for AWS::ElasticLoadBalancingV2::Listener is 'DefaultActions' (plural), not 'DefaultAction' (singular). Fixed in: - TestServerlessApp.ALB/serverless.template (deployed template) - README.md ALB documentation example
There was a problem hiding this comment.
Pull request overview
Adds first-class Application Load Balancer (ALB) support to the Lambda Annotations source generator, including documentation, generator logic, and both unit + integration test coverage.
Changes:
- Introduces
ALBApiAttributeand updates the source generator to emit ALB-related CloudFormation resources (TargetGroup, ListenerRule, Lambda Permission). - Adds source-generator unit tests and snapshots for ALB generation.
- Adds a new ALB test serverless app plus integration tests and deployment assets.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| Libraries/test/TestServerlessApp/ALBEventExamples/ValidALBEvents.cs.txt | Adds ALB-valid sample inputs used by source generator verification tests. |
| Libraries/test/TestServerlessApp.ALB/TestServerlessApp.ALB.csproj | New ALB test Lambda project referencing annotations + ALB events libraries. |
| Libraries/test/TestServerlessApp.ALB/serverless.template | New integration-test template defining VPC/ALB infra and generated Lambda resources. |
| Libraries/test/TestServerlessApp.ALB/aws-lambda-tools-defaults.json | Adds defaults used by dotnet lambda deploy-serverless for ALB test deployment. |
| Libraries/test/TestServerlessApp.ALB/AssemblyAttributes.cs | Sets Lambda serializer for the ALB test app. |
| Libraries/test/TestServerlessApp.ALB/ALBFunctions.cs | Implements hello + health endpoints annotated with ALBApi. |
| Libraries/test/TestServerlessApp.ALB.IntegrationTests/TestServerlessApp.ALB.IntegrationTests.csproj | New xUnit integration test project for ALB scenario. |
| Libraries/test/TestServerlessApp.ALB.IntegrationTests/DeploymentScript.ps1 | Deploys the ALB test stack (bucket + serverless deploy). |
| Libraries/test/TestServerlessApp.ALB.IntegrationTests/ALBTargetTests.cs | Exercises ALB endpoints and basic target-group existence checks. |
| Libraries/test/TestServerlessApp.ALB.IntegrationTests/ALBIntegrationTestContextFixtureCollection.cs | xUnit collection wiring for shared ALB fixture. |
| Libraries/test/TestServerlessApp.ALB.IntegrationTests/ALBIntegrationTestContextFixture.cs | Provisions/tears down ALB stack and exposes ALB DNS + clients. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/ALBEventsTests.cs | Adds CloudFormation writer tests for ALB resources and options. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs | Adds Verify-based generator test for ALB events. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/albEvents.template | Snapshot of expected ALB CloudFormation output. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ALB/ValidALBEvents_Hello_Generated.g.cs | Snapshot of generated handler for ALB hello method. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ALB/ValidALBEvents_HandleRequest_Generated.g.cs | Snapshot of generated handler for ALB async method. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/CSharpSourceGeneratorVerifier.cs | Adds ALB events assembly reference to the Roslyn test harness. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj | Adds project reference for Amazon.Lambda.ApplicationLoadBalancerEvents. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/ALBApiModelTests.cs | Tests for TypeFullNames/EventType additions and ALB return-type detection. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/ALBApiAttributeTests.cs | Unit tests for ALBApiAttribute defaults and validation. |
| Libraries/src/Amazon.Lambda.Annotations/README.md | Documents the new ALBApi attribute and generated resources. |
| Libraries/src/Amazon.Lambda.Annotations/ALB/ALBApiAttribute.cs | Introduces the ALB method attribute + validation logic. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs | Generates ALB Permission/TargetGroup/ListenerRule resources in templates. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Validation/LambdaFunctionValidator.cs | Adds dependency validation for ALB events assembly. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/TypeFullNames.cs | Adds ALB-related type constants and includes ALBApi in event set. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/SyntaxReceiver.cs | Recognizes ALBApiAttribute as an event attribute for discovery. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/LambdaMethodModel.cs | Adds helper for detecting ALB response return types. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/GeneratedMethodModelBuilder.cs | Ensures ALB functions are modeled as returning ALB response types. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventTypeBuilder.cs | Adds ALB event type detection. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventType.cs | Adds EventType.ALB. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/AttributeModelBuilder.cs | Builds ALBApi attribute models during analysis. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/ALBApiAttributeBuilder.cs | Parses constructor + named args into ALBApiAttribute instances. |
| Libraries/Libraries.sln | Adds new ALB test projects to the solution. |
| Libraries/Amazon.Lambda.Annotations.slnf | Adds ALB-related projects to the solution filter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Validation/LambdaFunctionValidator.cs
Show resolved
Hide resolved
Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs
Show resolved
Hide resolved
Libraries/test/TestServerlessApp.ALB.IntegrationTests/ALBIntegrationTestContextFixture.cs
Show resolved
Hide resolved
Libraries/test/TestServerlessApp.ALB.IntegrationTests/ALBIntegrationTestContextFixture.cs
Outdated
Show resolved
Hide resolved
Libraries/test/TestServerlessApp.ALB.IntegrationTests/ALBTargetTests.cs
Outdated
Show resolved
Hide resolved
1. Add ValidateAlbEvents() to LambdaFunctionValidator - validates ALBApiAttribute properties, method signature (ApplicationLoadBalancerRequest), and return type (ApplicationLoadBalancerResponse). Adds AWSLambda0132 diagnostic descriptor and registers in AnalyzerReleases.Unshipped.md. 2. Track ALB resources in metadata for orphan cleanup - ProcessAlbApiAttribute now returns resource names, tracked in Metadata.SyncedAlbResources. New SynchronizeAlbResources() removes orphaned Permission/TargetGroup/ ListenerRule resources when [ALBApi] is removed or ResourceName changes. 3. Fix runtime mismatch in README - change dotnet8 to dotnet6 in the Generated CloudFormation Resources example to match snapshots. 4. Restore function-architecture in integration test cleanup - DisposeAsync now resets function-architecture to x86_64 alongside s3-bucket/stack-name. 5. Replace fixed 30s delay with polling - WaitForTargetsHealthy() polls ALB target health with bounded 120s timeout instead of hard-coded sleep. 6. Scope target group query to stack's ALB - VerifyTargetGroupsExist now queries by LoadBalancerArn instead of all target groups in the account.
- ALBApiAttribute_TracksSyncedAlbResourcesInMetadata: verifies SyncedAlbResources metadata is persisted with all 3 resource names - ALBApiAttribute_RemovesOrphanedResourcesWhenAttributeRemoved: verifies ALB resources are cleaned up when [ALBApi] is removed from a function (two-pass test) - ALBApiAttribute_RemovesOldResourcesWhenResourceNameChanges: verifies old resources are removed and new ones created when ResourceName changes (two-pass test) - Updated albEvents.template snapshot to include SyncedAlbResources
…nerArn When a user provides an @ResourceName reference in [ALBApi] ListenerArn that doesn't match any resource or parameter in the existing template, a warning diagnostic (AWSLambda0133) is reported at compile time: 'The ALBApi ListenerArn references @FooListener, but no resource or parameter named FooListener was found in the CloudFormation template. The deployment may fail if this resource is not defined.' The warning is skipped for brand-new templates (empty/generated from scratch) since the user hasn't had a chance to add infrastructure yet.
Change AWSLambda0133 from DiagnosticSeverity.Warning to Error so invalid @references produce compile errors, catching typos early. The diagnostic always fires (no new-template exemption). The snapshot test VerifyValidALBEvents properly expects the error since the test starts from an empty template where @MyALBListener doesn't exist yet.
|
|
||
| | Property | Type | Required | Default | Description | | ||
| |---|---|---|---|---| | ||
| | `ListenerArn` | `string` | Yes | — | The ARN of the existing ALB listener, or a `@ResourceName` reference to a listener resource defined in the CloudFormation template. | |
There was a problem hiding this comment.
The reason we specify the listener instead of the actual ALB is because an ALB can have multiple listeners, and the listener is the one that has all of the configuration values
|
|
||
| // Validate method parameters - When using ALBApiAttribute, the method signature must be | ||
| // (ApplicationLoadBalancerRequest request) or (ApplicationLoadBalancerRequest request, ILambdaContext context) | ||
| var parameters = lambdaFunctionModel.LambdaMethod.Parameters; |
There was a problem hiding this comment.
The ALB attributes should act like the API Gateway attributes supporting all of the FromX attributes and by supporting that the customer function can have any number of parameters. Althought a difference I see is ALB does not support the idea of resource path templates like API Gateway does. So you might have to exclude that and if there are any parameters not mapping to something that should cause a diagnostic error.
There was a problem hiding this comment.
updated to add support for fromX and other attributes. but one issue is that all of these attributes are in api gateway namespace.
so in the users code they would need to import that (like this 3c2c696) which seems weird.
Should i create duplicate attributes or wondering if we can make breaking change to make it in some common namespace?
There was a problem hiding this comment.
i duplicated the attributes in 311bcd6 as per slack thread
| /// See <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html">ALB Lambda documentation</a>. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.Method)] | ||
| public class ALBApiAttribute : Attribute |
There was a problem hiding this comment.
My understanding besides host-header you should be able to setup a role for any arbitrary header like the following:
{
"Field": "http-header",
"HttpHeaderConfig": {
"HttpHeaderName": "X-Environment",
"Values": ["dev"]
}
}
I don't see an property on the attribute for setting that up.
Add two new diagnostic descriptors: - AWSLambda0134: FromRouteNotSupportedOnAlb - error when [FromRoute] is used on ALB functions since ALB does not support route path template parameters - AWSLambda0135: AlbUnmappedParameter - error when an ALB function parameter has no binding attribute ([FromHeader], [FromQuery], [FromBody], [FromServices], or known types)
…through Add ALBRequests check to HasConvertibleParameter so that ApplicationLoadBalancerRequest parameters are treated as pass-through (no conversion needed), matching the behavior of API Gateway request types.
Add ALB case to BuildParameters that generates __request__ (ApplicationLoadBalancerRequest) and __context__ (ILambdaContext) parameters for the generated method. This enables ALB functions to use FromX attributes with any number of parameters, matching the API Gateway pattern.
Add T4 template and generated code for resolving ALB function parameters: - [FromQuery] reads from QueryStringParameters or MultiValueQueryStringParameters - [FromHeader] reads from Headers or MultiValueHeaders - [FromBody] reads from Body (with JSON deserialization for complex types) - [FromServices] resolves from DI container - ILambdaContext and ApplicationLoadBalancerRequest are pass-through - MultiValueHeaders flag from ALBApiAttribute controls single/multi-value mode - Returns 400 Bad Request with validation errors on conversion failures
…ping Add T4 template and generated code for invoking ALB Lambda functions: - Pass-through when user returns ApplicationLoadBalancerResponse directly - Wraps non-ALB return types in ApplicationLoadBalancerResponse with proper Content-Type - Handles void, Task, value types, strings, and complex types - Serializes complex return types to JSON body
Add EventType.ALB case to the template dispatch chain in LambdaFunctionTemplate. When an ALB event is detected, the template now uses ALBSetupParameters for parameter binding and ALBInvoke for method invocation, matching the pattern used by API Gateway and Authorizer events.
…stics Replace strict 2-parameter signature check with flexible parameter validation: - [FromRoute] on ALB -> diagnostic error (ALB doesn't support route path templates) - Unmapped parameters -> diagnostic error (must use FromHeader/FromQuery/FromBody/FromServices) - [FromQuery] type validation (primitive types only) - Attribute name validation for FromQuery and FromHeader - Allow ALB events to use FromX parameter attributes without ApiParametersOnNonApiFunction error
- Add ALB functions using [FromQuery], [FromHeader], and [FromBody] to TestServerlessApp.ALB - Add unit tests for ParameterListExtension with ALB types - Add unit tests for new diagnostic descriptors (AWSLambda0134, AWSLambda0135) - Add unit tests for FromQuery/FromHeader Name property behavior - Update ALB snapshot files to reflect new ALB template code generation (param doc changes, invoke pattern using var response)
Add HttpHeaderConditionName and HttpHeaderConditionValues properties to ALBApiAttribute for configuring http-header listener rule conditions. This generates CloudFormation with the proper HttpHeaderConfig nested structure:
{
"Field": "http-header",
"HttpHeaderConfig": {
"HttpHeaderName": "X-Environment",
"Values": ["dev", "staging"]
}
}
- Both properties must be set together (validated)
- Supports wildcard characters (* and ?)
- Updated ALBApiAttributeBuilder to parse new named arguments
- Updated CloudFormationWriter to generate the condition
- Added unit tests for validation and property behavior
Add QueryStringConditions and SourceIpConditions properties to ALBApiAttribute.
QueryStringConditions uses 'key=value' format strings that generate:
{ Field: 'query-string', QueryStringConfig: { Values: [{ Key: 'version', Value: 'v1' }] } }
Use '=value' (empty key prefix) to match any key.
SourceIpConditions uses CIDR block strings that generate:
{ Field: 'source-ip', SourceIpConfig: { Values: ['192.0.2.0/24'] } }
Supports both IPv4 and IPv6 CIDR formats.
- Updated ALBApiAttributeBuilder to parse new array named arguments
- Updated CloudFormationWriter to generate both condition types
- Added unit tests for property defaults, values, and combined conditions
…mespace Create duplicate FromX attributes in the Amazon.Lambda.Annotations.ALB namespace so ALB users don't need to import the APIGateway namespace. Users now only need: using Amazon.Lambda.Annotations; // [LambdaFunction], [FromServices] using Amazon.Lambda.Annotations.ALB; // [ALBApi], [FromHeader], [FromQuery], [FromBody] - Created ALB/FromHeaderAttribute.cs, ALB/FromQueryAttribute.cs, ALB/FromBodyAttribute.cs - Added TypeFullNames constants: ALBFromQueryAttribute, ALBFromHeaderAttribute, ALBFromBodyAttribute - Added ALBFromQueryAttributeBuilder and ALBFromHeaderAttributeBuilder - Updated AttributeModelBuilder to recognize the ALB namespace attributes - Updated ALBSetupParameters template to only check ALB namespace attributes - Updated LambdaFunctionValidator to use ALB namespace attributes for ALB validation - Updated ParameterListExtension to recognize ALB FromBody for string pass-through - Fixed ambiguous reference issues by fully qualifying types in tests
CloudFormation rejects flat 'Values' arrays for ALB listener rule conditions. Per the AWS ELB API (RuleCondition), each condition type must use its corresponding *Config sub-object: - path-pattern -> PathPatternConfig.Values - host-header -> HostHeaderConfig.Values - http-request-method -> HttpRequestMethodConfig.Values The http-header, query-string, and source-ip conditions already used the correct *Config format. Updated CloudFormationWriter.ProcessAlbApiAttribute and the albEvents.template snapshot. Added ALBApiAttribute_ConditionsUseConfigSubObjects test verifying all 6 condition types use proper *Config structure.
| @@ -0,0 +1,17 @@ | |||
| using Amazon.Lambda.Annotations.SourceGenerator.Models; | |||
There was a problem hiding this comment.
missing the license header
| @@ -0,0 +1,25 @@ | |||
| using Amazon.Lambda.Annotations.ALB; | |||
There was a problem hiding this comment.
missing the license header
| @@ -0,0 +1,25 @@ | |||
| using Amazon.Lambda.Annotations.ALB; | |||
There was a problem hiding this comment.
missing the license header
| @@ -0,0 +1,65 @@ | |||
| using Amazon.Lambda.Annotations.ALB; | |||
There was a problem hiding this comment.
missing the license header
| @@ -0,0 +1,98 @@ | |||
| <#@ template language="C#" #> | |||
There was a problem hiding this comment.
not sure if we add a license header for the tt
| @@ -1,4 +1,5 @@ | |||
| using Amazon.Lambda.Annotations.SourceGenerator.Diagnostics; | |||
| using Amazon.Lambda.Annotations.ALB; | |||
There was a problem hiding this comment.
missing the license header
| @@ -0,0 +1,185 @@ | |||
| using System; | |||
There was a problem hiding this comment.
missing the license header
| @@ -0,0 +1,15 @@ | |||
| using System; | |||
There was a problem hiding this comment.
missing the license header
| "Tool": "Amazon.Lambda.Annotations" | ||
| }, | ||
| "Properties": { | ||
| "Runtime": "dotnet6", |
| "Properties": { | ||
| "Runtime": "dotnet6", | ||
| "CodeUri": ".", | ||
| "MemorySize": 256, |
Application Load Balancer (ALB) Support for Lambda Annotations
#2269
Overview
This PR adds a new
[ALBApi]attribute to the Lambda Annotations framework, enabling developers to configure Lambda functions as targets behind an Application Load Balancer using the same declarative, attribute-driven approach already available for API Gateway ([HttpApi],[RestApi]) and SQS ([SQSEvent]).User Experience
Developers can now wire a Lambda function to an ALB listener with a single attribute:
The source generator automatically creates the necessary CloudFormation resources —
AWS::Lambda::Permission,AWS::ElasticLoadBalancingV2::TargetGroup, andAWS::ElasticLoadBalancingV2::ListenerRule— and keeps them in sync with the code.ALBApiAttribute PropertiesListenerArn@ResourceNametemplate referencePathPattern"/api/orders/*")PriorityMultiValueHeadersHostHeaderHttpMethod"GET","POST")ResourceNameKey Design Decisions
Eventsproperty, ALB integration requires generating separate top-level CloudFormation resources (TargetGroup, ListenerRule, Permission). This is because AWS SAM does not have a built-in ALB event type.@ResourceNamepattern — Follows the same convention as other annotations attributes for referencing CloudFormation resources usingRef.Testing