Add [ScheduleEvent] annotation attribute and source generator support#2323
Open
GarrettBeatty wants to merge 1 commit intofeature/dynamodb-annotationsfrom
Open
Add [ScheduleEvent] annotation attribute and source generator support#2323GarrettBeatty wants to merge 1 commit intofeature/dynamodb-annotationsfrom
GarrettBeatty wants to merge 1 commit intofeature/dynamodb-annotationsfrom
Conversation
b1c1d26 to
53f2edd
Compare
There was a problem hiding this comment.
Pull request overview
Adds first-class [ScheduleEvent] support to the Lambda Annotations framework so schedule-triggered Lambdas (rate/cron) can be declared in C# and emitted into the generated SAM/CloudFormation template.
Changes:
- Introduces
ScheduleEventAttribute(schedule expression + optional ResourceName/Description/Input/Enabled). - Extends the source generator to recognize/validate schedule events and emit
Type: Scheduleevent configuration in the template. - Adds unit, snapshot, and integration tests plus docs/examples for schedule events.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Libraries/test/TestServerlessApp/TestServerlessApp.csproj | Adds CloudWatchEvents project reference for schedule event sample app. |
| Libraries/test/TestServerlessApp/ScheduledProcessing.cs | Adds an example scheduled handler Lambda using [ScheduleEvent]. |
| Libraries/test/TestServerlessApp/ScheduleEventExamples/ValidScheduleEvents.cs.txt | Adds valid schedule event usages for generator snapshot tests (kept as .txt). |
| Libraries/test/TestServerlessApp.IntegrationTests/TestServerlessApp.IntegrationTests.csproj | Adds AWSSDK.CloudWatchEvents dependency for schedule integration testing. |
| Libraries/test/TestServerlessApp.IntegrationTests/ScheduleEventRule.cs | Adds integration test to validate the deployed EventBridge rule configuration. |
| Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs | Updates expected Lambda function count to include the new scheduled handler. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/ScheduleEventsTests.cs | Adds CloudFormation writer tests for schedule event emission and property syncing. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs | Adds snapshot-based source generator test for valid schedule events. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/scheduleEvents.template | Adds expected generated serverless template snapshot for schedule events. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Schedule/ValidScheduleEvents_ProcessScheduledEvent_Generated.g.cs | Adds expected generated handler snapshot (sync). |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/Schedule/ValidScheduleEvents_ProcessScheduledEventAsync_Generated.g.cs | Adds expected generated handler snapshot (async). |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/ScheduleEventAttributeTests.cs | Adds unit tests for ScheduleEventAttribute defaults/derivations/validation. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/CSharpSourceGeneratorVerifier.cs | Adds metadata reference for ScheduledEvent type in the Roslyn test harness. |
| Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Amazon.Lambda.Annotations.SourceGenerators.Tests.csproj | Adds CloudWatchEvents project reference for tests. |
| Libraries/src/Amazon.Lambda.Annotations/Schedule/ScheduleEventAttribute.cs | Introduces the new ScheduleEventAttribute implementation + validation. |
| Libraries/src/Amazon.Lambda.Annotations/README.md | Documents ScheduleEvent usage and updates supported-attributes list. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs | Emits Schedule SAM event entries for [ScheduleEvent]. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Validation/LambdaFunctionValidator.cs | Adds dependency checks + signature/return/attribute validation for schedule handlers. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/TypeFullNames.cs | Adds full-name constants for ScheduleEventAttribute and ScheduledEvent. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/SyntaxReceiver.cs | Recognizes ScheduleEventAttribute during syntax collection. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventTypeBuilder.cs | Maps ScheduleEventAttribute to EventType.Schedule. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/ScheduleEventAttributeBuilder.cs | Builds ScheduleEventAttribute models from Roslyn attribute data. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/AttributeModelBuilder.cs | Routes ScheduleEventAttribute to the new builder/model type. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs | Adds a new diagnostic descriptor for invalid ScheduleEventAttribute usage. |
| Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Unshipped.md | Records the new diagnostic ID in analyzer release notes. |
| .autover/changes/add-scheduleevent-annotation.json | Adds versioning/changelog entry for the new feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
53f2edd to
ae98bbc
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 30 out of 30 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- ScheduleEventAttribute with Schedule (rate/cron), ResourceName, Description, Input, Enabled - ScheduleEventAttributeBuilder for Roslyn AttributeData parsing - Source generator wiring (TypeFullNames, SyntaxReceiver, EventTypeBuilder, AttributeModelBuilder) - CloudFormationWriter ProcessScheduleAttribute (SAM Schedule event rule) - LambdaFunctionValidator ValidateScheduleEvents - DiagnosticDescriptors InvalidScheduleEventAttribute - ScheduleEventAttributeTests (attribute unit tests) - ScheduleEventsTests (CloudFormation writer tests) - E2E source generator snapshot tests - Integration test (ScheduleEventRule) - Sample function (ScheduledProcessing) - .autover change file - README documentation update pr comments update test update test
c528158 to
05e42e2
Compare
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.
Summary
Adds
[ScheduleEvent]annotation attribute support to the Lambda Annotations framework, enabling developers to declaratively configure schedule-triggered Lambda functions directly in C# code using rate or cron expressions. The source generator automatically produces the corresponding SAM/CloudFormation template configuration at build time.User Experience
With this change, developers can write schedule-triggered Lambda functions like this:
The source generator will automatically generate the SAM template entry:
Attribute Properties
Schedulerate(...)orcron(...))ResourceNameDescriptionInputEnabledtrueCompile-Time Validation
The source generator validates at build time:
rate(orcron(ScheduledEvent, optional second parameter must beILambdaContextvoidorTaskAmazon.Lambda.CloudWatchEventsNuGet packageExample with all properties
What Changed
Annotation Attribute (
Amazon.Lambda.Annotations)ScheduleEventAttributeclass inAmazon.Lambda.Annotations.Schedulenamespace with configurable properties and built-in validationSource Generator (
Amazon.Lambda.Annotations.SourceGenerator)ScheduleEventAttributeBuilder— extracts attribute data from Roslyn syntax treeAttributeModelBuilder— recognizes and routes ScheduleEvent attributesEventTypeBuilder— maps toEventType.ScheduleSyntaxReceiver— registers ScheduleEvent as a recognized attributeTypeFullNames— adds Schedule type constantsLambdaFunctionValidator— validates method signatures, return types, dependencies, and attribute propertiesCloudFormationWriter.ProcessScheduleAttribute()— generates SAM template with Schedule expression, Description, Input, and EnabledAWSLambda0132for invalid ScheduleEventAttribute errorsTests
Related: DOTNET-8574