Skip to content

Commit 5820339

Browse files
Merge branch 'dev'
2 parents caea55b + 8d87c21 commit 5820339

38 files changed

Lines changed: 1201 additions & 22 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Release 2026-04-16
2+
3+
### Amazon.Lambda.Annotations (1.14.0)
4+
* Added [SNSEvent] annotation attribute for declaratively configuring SNS topic-triggered Lambda functions with support for topic reference, filter policy, and enabled state.
5+
16
## Release 2026-04-14
27

38
### Amazon.Lambda.TestTool.BlazorTester (0.17.1)

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Amazon.Lambda.Annotations.SourceGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
2121
<IncludeBuildOutput>false</IncludeBuildOutput>
2222

23-
<Version>1.13.0</Version>
23+
<Version>1.14.0</Version>
2424
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2525
</PropertyGroup>
2626

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/AnalyzerReleases.Unshipped.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ AWSLambda0133 | AWSLambdaCSharpGenerator | Error | ALB Listener Reference Not Fo
2121
AWSLambda0134 | AWSLambdaCSharpGenerator | Error | FromRoute not supported on ALB functions
2222
AWSLambda0135 | AWSLambdaCSharpGenerator | Error | Unmapped parameter on ALB function
2323
AWSLambda0136 | AWSLambdaCSharpGenerator | Error | Invalid S3EventAttribute
24+
AWSLambda0138 | AWSLambdaCSharpGenerator | Error | Invalid SNSEventAttribute

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,5 +281,12 @@ public static class DiagnosticDescriptors
281281
category: "AWSLambdaCSharpGenerator",
282282
DiagnosticSeverity.Error,
283283
isEnabledByDefault: true);
284+
285+
public static readonly DiagnosticDescriptor InvalidSnsEventAttribute = new DiagnosticDescriptor(id: "AWSLambda0138",
286+
title: "Invalid SNSEventAttribute",
287+
messageFormat: "Invalid SNSEventAttribute encountered: {0}",
288+
category: "AWSLambdaCSharpGenerator",
289+
DiagnosticSeverity.Error,
290+
isEnabledByDefault: true);
284291
}
285292
}

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/AttributeModelBuilder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ public static AttributeModel Build(AttributeData att, GeneratorExecutionContext
113113
Type = TypeModelBuilder.Build(att.AttributeClass, context)
114114
};
115115
}
116+
else if (att.AttributeClass.Equals(context.Compilation.GetTypeByMetadataName(TypeFullNames.SNSEventAttribute), SymbolEqualityComparer.Default))
117+
{
118+
var data = SNSEventAttributeBuilder.Build(att);
119+
model = new AttributeModel<SNS.SNSEventAttribute>
120+
{
121+
Data = data,
122+
Type = TypeModelBuilder.Build(att.AttributeClass, context)
123+
};
124+
}
116125
else if (att.AttributeClass.Equals(context.Compilation.GetTypeByMetadataName(TypeFullNames.HttpApiAuthorizerAttribute), SymbolEqualityComparer.Default))
117126
{
118127
var data = HttpApiAuthorizerAttributeBuilder.Build(att);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using Amazon.Lambda.Annotations.SNS;
5+
using Microsoft.CodeAnalysis;
6+
using System;
7+
8+
namespace Amazon.Lambda.Annotations.SourceGenerator.Models.Attributes
9+
{
10+
/// <summary>
11+
/// Builder for <see cref="SNSEventAttribute"/>.
12+
/// </summary>
13+
public class SNSEventAttributeBuilder
14+
{
15+
public static SNSEventAttribute Build(AttributeData att)
16+
{
17+
if (att.ConstructorArguments.Length != 1)
18+
{
19+
throw new NotSupportedException($"{TypeFullNames.SNSEventAttribute} must have constructor with 1 argument.");
20+
}
21+
var topic = att.ConstructorArguments[0].Value as string;
22+
var data = new SNSEventAttribute(topic);
23+
24+
foreach (var pair in att.NamedArguments)
25+
{
26+
if (pair.Key == nameof(data.ResourceName) && pair.Value.Value is string resourceName)
27+
{
28+
data.ResourceName = resourceName;
29+
}
30+
else if (pair.Key == nameof(data.FilterPolicy) && pair.Value.Value is string filterPolicy)
31+
{
32+
data.FilterPolicy = filterPolicy;
33+
}
34+
else if (pair.Key == nameof(data.Enabled) && pair.Value.Value is bool enabled)
35+
{
36+
data.Enabled = enabled;
37+
}
38+
}
39+
40+
return data;
41+
}
42+
}
43+
}

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public enum EventType
99
API,
1010
S3,
1111
SQS,
12+
SNS,
1213
DynamoDB,
1314
Schedule,
1415
Authorizer,

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/EventTypeBuilder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public static HashSet<EventType> Build(IMethodSymbol lambdaMethodSymbol,
3434
{
3535
events.Add(EventType.S3);
3636
}
37+
else if (attribute.AttributeClass.ToDisplayString() == TypeFullNames.SNSEventAttribute)
38+
{
39+
events.Add(EventType.SNS);
40+
}
3741
else if (attribute.AttributeClass.ToDisplayString() == TypeFullNames.HttpApiAuthorizerAttribute
3842
|| attribute.AttributeClass.ToDisplayString() == TypeFullNames.RestApiAuthorizerAttribute)
3943
{

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/SyntaxReceiver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ internal class SyntaxReceiver : ISyntaxContextReceiver
2727
{ "FunctionUrlAttribute", "FunctionUrl" },
2828
{ "SQSEventAttribute", "SQSEvent" },
2929
{ "ALBApiAttribute", "ALBApi" },
30-
{ "S3EventAttribute", "S3Event" }
30+
{ "S3EventAttribute", "S3Event" },
31+
{ "SNSEventAttribute", "SNSEvent" }
3132
};
3233

3334
public List<MethodDeclarationSyntax> LambdaMethods { get; } = new List<MethodDeclarationSyntax>();

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/TypeFullNames.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public static class TypeFullNames
6262
public const string S3Event = "Amazon.Lambda.S3Events.S3Event";
6363
public const string S3EventAttribute = "Amazon.Lambda.Annotations.S3.S3EventAttribute";
6464

65+
public const string SNSEvent = "Amazon.Lambda.SNSEvents.SNSEvent";
66+
public const string SNSEventAttribute = "Amazon.Lambda.Annotations.SNS.SNSEventAttribute";
67+
6568
public const string LambdaSerializerAttribute = "Amazon.Lambda.Core.LambdaSerializerAttribute";
6669
public const string DefaultLambdaSerializer = "Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer";
6770

@@ -91,7 +94,8 @@ public static class TypeFullNames
9194
FunctionUrlAttribute,
9295
SQSEventAttribute,
9396
ALBApiAttribute,
94-
S3EventAttribute
97+
S3EventAttribute,
98+
SNSEventAttribute
9599
};
96100
}
97101
}

0 commit comments

Comments
 (0)