Add [ScheduleEvent] annotation attribute and source generator support#2323
Add [ScheduleEvent] annotation attribute and source generator support#2323GarrettBeatty wants to merge 8 commits intodevfrom
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.
- DynamoDBEventAttribute with Stream, ResourceName, BatchSize, StartingPosition, MaximumBatchingWindowInSeconds, Filters, Enabled - DynamoDBEventAttributeBuilder for Roslyn AttributeData parsing - Source generator wiring (TypeFullNames, SyntaxReceiver, EventTypeBuilder, AttributeModelBuilder) - CloudFormationWriter ProcessDynamoDBAttribute (SAM DynamoDB event source mapping) - LambdaFunctionValidator ValidateDynamoDBEvents - DiagnosticDescriptors InvalidDynamoDBEventAttribute (AWSLambda0132) - DynamoDBEventAttributeTests (attribute unit tests) - DynamoDBEventsTests (CloudFormation writer tests) - E2E source generator snapshot tests - Integration test (DynamoDBEventSourceMapping) - Sample function (DynamoDbStreamProcessing) - .autover change file - README documentation pr comments
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
normj
left a comment
There was a problem hiding this comment.
Approved with a small feature request. I'll let you decide if you want to add it.
| /// <summary> | ||
| /// A JSON string to pass as input to the Lambda function. | ||
| /// </summary> | ||
| public string Input { get; set; } = null; |
There was a problem hiding this comment.
Feature suggestion: I doubt too many people want to put large JSON documents in this attribute. You could make the logic look to see if this is a file path, relative or absolute, and if it is read the file and put that in the template. If you do think this is worth adding be sure the comment block for Input calls out this can be a file path.
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
Manual Testing
Related: DOTNET-8574