Add [SNSEvent] annotation attribute and source generator support#2322
Add [SNSEvent] annotation attribute and source generator support#2322GarrettBeatty wants to merge 6 commits intodevfrom
Conversation
acfc470 to
53e14ec
Compare
There was a problem hiding this comment.
Pull request overview
Adds first-class SNS event support to the Lambda Annotations framework by introducing a new [SNSEvent] attribute, validating its usage at compile time, and emitting the corresponding SAM/CloudFormation SNS event configuration via the source generator.
Changes:
- Introduces
SNSEventAttribute(with Topic/ResourceName/FilterPolicy/Enabled) and updates docs/examples. - Extends the source generator pipeline (syntax discovery, modeling, validation, template writing) to support SNS events and diagnostics.
- Adds unit tests, snapshot tests, and an integration test to validate generated templates and real SNS subscription configuration.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| Libraries/test/TestServerlessApp/TestServerlessApp.csproj | Adds SNSEvents project reference for test app compilation. |
| Libraries/test/TestServerlessApp/SnsMessageProcessing.cs | Adds an SNS-triggered Lambda handler using [SNSEvent]. |
| Libraries/test/TestServerlessApp/SNSEventExamples/ValidSNSEvents.cs.txt | Adds valid SNS examples used as generator test input (not deployed). |
| Libraries/test/TestServerlessApp.IntegrationTests/SNSEventSubscription.cs | Adds integration test to verify SNS subscription + filter policy. |
| Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs | Captures SNS Topic ARN from the deployed stack; updates expected Lambda count. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/SNSEventsTests.cs | Adds CloudFormation writer tests for SNS event emission and syncing behavior. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs | Adds end-to-end snapshot-based generator test for SNS events. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/snsEvents.template | Adds expected generated serverless template snapshot for SNS events. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SNS/ValidSNSEvents_ProcessMessages_Generated.g.cs | Adds expected generated handler snapshot (sync). |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SNS/ValidSNSEvents_ProcessMessagesAsync_Generated.g.cs | Adds expected generated handler snapshot (async). |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SNSEventAttributeTests.cs | Adds unit tests for SNSEventAttribute defaults and validation. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/CSharpSourceGeneratorVerifier.cs | Adds SNSEvents metadata reference for compilation in generator tests. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj | Adds SNSEvents project reference for test project. |
| Libraries/src/Amazon.Lambda.Annotations/SNS/SNSEventAttribute.cs | Introduces the public [SNSEvent] attribute and internal validation helpers. |
| Libraries/src/Amazon.Lambda.Annotations/README.md | Documents SNS event usage and adds an SNS example section. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs | Emits Type: SNS event definitions and associated properties into templates. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Validation/LambdaFunctionValidator.cs | Adds SNS signature/return-type/attribute validation and dependency check. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/TypeFullNames.cs | Adds SNS type/attribute full names and registers SNS attribute in known list. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/SyntaxReceiver.cs | Recognizes SNSEventAttribute during syntax collection. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventTypeBuilder.cs | Maps SNSEventAttribute to EventType.SNS. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventType.cs | Adds the SNS enum value. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/SNSEventAttributeBuilder.cs | Builds SNSEventAttribute models from Roslyn attribute data. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/AttributeModelBuilder.cs | Routes SNSEventAttribute into the attribute model pipeline. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs | Adds a diagnostic descriptor for invalid SNSEventAttribute usage. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Unshipped.md | Registers the new SNS diagnostic in analyzer releases. |
| .autover/changes/add-snsevent-annotation.json | Adds a minor-version changelog entry for the new SNS annotation support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- SNSEventAttribute with Topic, ResourceName, FilterPolicy, Enabled - SNSEventAttributeBuilder for Roslyn AttributeData parsing - Source generator wiring (TypeFullNames, SyntaxReceiver, EventTypeBuilder, AttributeModelBuilder) - CloudFormationWriter ProcessSNSAttribute (SAM SNS event subscription) - LambdaFunctionValidator ValidateSNSEvents - DiagnosticDescriptors InvalidSNSEventAttribute - SNSEventAttributeTests (attribute unit tests) - SNSEventsTests (CloudFormation writer tests) - E2E source generator snapshot tests - Integration test (SNSEventSubscription) - Sample function (SnsMessageProcessing) - .autover change file - README documentation
52b4e4f to
60111c9
Compare
| public bool Enabled | ||
| { | ||
| get => enabled.GetValueOrDefault(); | ||
| get => enabled.GetValueOrDefault(true); |
There was a problem hiding this comment.
i think this was a bug. default should be true as per the docs. right now it returns false by default
There was a problem hiding this comment.
Call that out in the changelog
There was a problem hiding this comment.
Pull request overview
Adds first-class SNS event support to the Lambda Annotations framework by introducing a new [SNSEvent] attribute and extending the source generator to validate SNS handlers and emit the corresponding SAM Events configuration.
Changes:
- Introduces
Amazon.Lambda.Annotations.SNS.SNSEventAttributewith optionalResourceName,FilterPolicy, andEnabled. - Extends the source generator to recognize/validate
[SNSEvent]and writeType: SNSevents into generated templates. - Adds unit, snapshot, writer, and integration tests plus documentation updates for SNS usage.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Libraries/test/TestServerlessApp/TestServerlessApp.csproj | Adds SNSEvents project reference for test app compilation. |
| Libraries/test/TestServerlessApp/SnsMessageProcessing.cs | Adds a deployable SNS-triggered handler example for integration testing. |
| Libraries/test/TestServerlessApp/SNSEventExamples/ValidSNSEvents.cs.txt | Adds source input for SNS-related generator snapshot tests (not deployed). |
| Libraries/test/TestServerlessApp.IntegrationTests/SNSEventSubscription.cs | Adds integration test verifying SNS subscription + filter policy. |
| Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs | Captures SNS topic ARN from the deployed stack for tests. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/SNSEventsTests.cs | Adds CloudFormation writer tests for SNS event serialization + syncing. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs | Adds snapshot-based generator test coverage for valid SNS handlers. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/snsEvents.template | Adds expected serverless template snapshot for SNS events. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SNS/ValidSNSEvents_ProcessMessages_Generated.g.cs | Adds expected generated handler snapshot (sync). |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/SNS/ValidSNSEvents_ProcessMessagesAsync_Generated.g.cs | Adds expected generated handler snapshot (async). |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SNSEventAttributeTests.cs | Adds unit tests for SNSEventAttribute defaults/validation. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/CSharpSourceGeneratorVerifier.cs | Adds SNSEvent assembly reference for Roslyn test compilation. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj | Adds SNSEvents project reference for test project. |
| Libraries/src/Amazon.Lambda.Annotations/SQS/SQSEventAttribute.cs | Fixes SQS Enabled default to true. |
| Libraries/src/Amazon.Lambda.Annotations/SNS/SNSEventAttribute.cs | Adds the new SNSEventAttribute API and validation helpers. |
| Libraries/src/Amazon.Lambda.Annotations/README.md | Documents SNS event usage and adds SNSEvent to attribute list. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs | Emits SNS SAM event entries and tracks synced properties. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Validation/LambdaFunctionValidator.cs | Adds SNS validation (dependencies, signature, return type, attribute validation). |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/TypeFullNames.cs | Registers SNSEvent and SNSEventAttribute full names. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/SyntaxReceiver.cs | Recognizes SNSEventAttribute as a “secondary” attribute requiring [LambdaFunction]. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventTypeBuilder.cs | Maps SNSEventAttribute to EventType.SNS. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventType.cs | Adds SNS to the event type enum. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/SNSEventAttributeBuilder.cs | Builds SNSEventAttribute instances from Roslyn AttributeData. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/AttributeModelBuilder.cs | Routes SNSEventAttribute through the model builder pipeline. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs | Adds Invalid SNSEventAttribute diagnostic descriptor. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Unshipped.md | Registers the new SNS diagnostic in unshipped analyzer releases. |
| .autover/changes/add-snsevent-annotation.json | Adds autover changelog entry for the new SNSEvent feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,40 @@ | |||
| using Amazon.Lambda.Annotations.SNS; | |||
| @@ -0,0 +1,113 @@ | |||
| using System; | |||
| public bool Enabled | ||
| { | ||
| get => enabled.GetValueOrDefault(); | ||
| get => enabled.GetValueOrDefault(true); |
There was a problem hiding this comment.
Call that out in the changelog
Summary
Adds
[SNSEvent]annotation attribute support to the Lambda Annotations framework, enabling developers to declaratively configure SNS topic-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 SNS-triggered Lambda functions like this:
The source generator will automatically generate the SAM template entry:
Attribute Properties
Topic@TopicNamefor CloudFormation Ref, or topic ARN)ResourceNameFilterPolicyEnabledtrueThe implementation is pretty similar to sqs event
Related: DOTNET-8573