Add [S3Event] annotation attribute and source generator support#2321
Add [S3Event] annotation attribute and source generator support#2321GarrettBeatty wants to merge 3 commits intodevfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class S3 event source support to Lambda Annotations by introducing an [S3Event] attribute and extending the source generator to emit the corresponding SAM S3 event configuration (plus validation and tests), mirroring the existing SQS event workflow.
Changes:
- Introduce
S3EventAttribute(Amazon.Lambda.Annotations) and wire it into the source generator (model building, validation, CloudFormation writing). - Add unit tests + sample inputs to validate S3 event template output and property syncing behavior.
- Extend the TestServerlessApp integration test stack/template to include an S3-triggered function and validate bucket notification configuration.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Libraries/test/TestServerlessApp/TestServerlessApp.csproj | Adds S3Events project reference for S3 event handler examples. |
| Libraries/test/TestServerlessApp/serverless.template | Adds generated S3 event function + S3 bucket resource to integration template. |
| Libraries/test/TestServerlessApp/S3EventExamples/ValidS3Events.cs.txt | Adds valid S3Event attribute usages for generator tests (non-deployed input). |
| Libraries/test/TestServerlessApp/S3EventExamples/S3EventProcessing.cs | Adds an S3-triggered Lambda function example for integration deployment. |
| Libraries/test/TestServerlessApp/aws-lambda-tools-defaults.json | Updates defaults for unique test bucket/stack naming used by deployment script. |
| Libraries/test/TestServerlessApp.IntegrationTests/S3EventNotification.cs | Adds integration test verifying S3 bucket notification configuration. |
| Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs | Adds S3 helper exposure + resolves deployed TestS3Bucket physical name; updates expected function count. |
| Libraries/test/TestServerlessApp.IntegrationTests/DeploymentScript.ps1 | Ensures TestS3Bucket resource exists in deployed template for S3 event testing. |
| Libraries/test/IntegrationTests.Helpers/S3Helper.cs | Adds helper to fetch S3 bucket notification configuration. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/S3EventsTests.cs | Adds CloudFormation writer tests for S3 event rendering and syncing. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj | Adds S3Events project reference for source generator tests. |
| Libraries/src/Amazon.Lambda.Annotations/S3/S3EventAttribute.cs | Introduces public [S3Event] attribute with validation and configurable properties. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs | Adds S3 event serialization into SAM template + synced metadata tracking. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Validation/LambdaFunctionValidator.cs | Adds dependency + signature validation for S3 event handlers and attribute validation diagnostics. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/TypeFullNames.cs | Registers S3 event types/attribute names for generator lookups. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/SyntaxReceiver.cs | Adds S3EventAttribute to attribute discovery map. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventTypeBuilder.cs | Adds S3 event type detection from attributes. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/S3EventAttributeBuilder.cs | Adds builder that materializes S3EventAttribute data from Roslyn AttributeData. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/AttributeModelBuilder.cs | Wires S3EventAttributeBuilder into attribute model construction. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs | Adds a dedicated diagnostic descriptor for invalid S3EventAttribute usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Libraries/test/TestServerlessApp.IntegrationTests/S3EventNotification.cs
Show resolved
Hide resolved
Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/S3EventsTests.cs
Show resolved
Hide resolved
- S3EventAttribute with Bucket (required), ResourceName, Events, FilterPrefix, FilterSuffix, Enabled - S3EventAttributeBuilder for Roslyn AttributeData parsing - TypeFullNames constants and Events hashset registration - SyntaxReceiver secondary attribute registration - EventTypeBuilder S3 event type mapping - AttributeModelBuilder S3 branch - CloudFormationWriter ProcessS3Attribute (SAM S3 event with Ref, Events list, Filter rules) - LambdaFunctionValidator ValidateS3Events (params, return type, dependency check) - DiagnosticDescriptors InvalidS3EventAttribute (AWSLambda0133) Add S3Event annotation tests - ValidS3Events.cs.txt test source with 3 test functions - S3EventsTests.cs CloudFormation writer tests (attribute application + property sync) - S3Events project references in TestServerlessApp.csproj and test project IT test PR comments change file
a5f4621 to
ac02c35
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Adds
[S3Event]annotation attribute support to the Lambda Annotations framework, enabling developers to declaratively configure S3 event-triggered Lambda functions directly in C# code. The source generator automatically produces the corresponding SAM/CloudFormation template configuration at build time.User Experience
With this change, developers can write S3-triggered Lambda functions like this:
The source generator will automatically generate the SAM template entry:
Attribute Properties
Bucket@to reference a CloudFormation resource)ResourceNameEventss3:ObjectCreated:*FilterPrefixuploads/)FilterSuffix.jpg)EnabledtrueCompile-Time Validation
The source generator validates at build time:
@(referencing a CloudFormation resource)S3Event, optional second parameter must beILambdaContextvoidorTask(S3 notifications are fire-and-forget)Amazon.Lambda.S3EventsNuGet packageExample with all properties
What Changed
Annotation Attribute (
Amazon.Lambda.Annotations)S3EventAttributeclass inAmazon.Lambda.Annotations.S3namespace with configurable properties and built-in validationSource Generator (
Amazon.Lambda.Annotations.SourceGenerator)S3EventAttributeBuilder— extracts attribute data from Roslyn syntax treeAttributeModelBuilder— recognizes and routes S3Event attributesEventTypeBuilder— maps toEventType.S3SyntaxReceiver— registers S3Event as a recognized attributeTypeFullNames— adds S3 type constantsLambdaFunctionValidator— validates method signatures, return types, dependencies, and attribute propertiesCloudFormationWriter.ProcessS3Attribute()— generates SAM template with Bucket (Ref), Events (list), Filter (S3Key rules), and EnabledAWSLambda0133for invalid S3EventAttribute errorsTests
Related: DOTNET-8572