Skip to content

Commit 7357a5b

Browse files
authored
Merge pull request #858 from aws-powertools/feature/appsync-events
chore: Feature/appsync events
2 parents e9550ff + 94fdcc2 commit 7357a5b

28 files changed

+3307
-1
lines changed

docs/core/event_handler/appsync_events.md

+714
Large diffs are not rendered by default.

libraries/AWS.Lambda.Powertools.sln

+30
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metrics", "Metrics", "{A566
105105
EndProject
106106
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOT-Function-ILogger", "tests\e2e\functions\core\logging\AOT-Function-ILogger\src\AOT-Function-ILogger\AOT-Function-ILogger.csproj", "{7FC6DD65-0352-4139-8D08-B25C0A0403E3}"
107107
EndProject
108+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.EventHandler.Tests", "tests\AWS.Lambda.Powertools.EventHandler.Tests\AWS.Lambda.Powertools.EventHandler.Tests.csproj", "{61374D8E-F77C-4A31-AE07-35DAF1847369}"
109+
EndProject
110+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.EventHandler", "src\AWS.Lambda.Powertools.EventHandler\AWS.Lambda.Powertools.EventHandler.csproj", "{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}"
111+
EndProject
108112
Global
109113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
110114
Debug|Any CPU = Debug|Any CPU
@@ -562,6 +566,30 @@ Global
562566
{7FC6DD65-0352-4139-8D08-B25C0A0403E3}.Release|x64.Build.0 = Release|Any CPU
563567
{7FC6DD65-0352-4139-8D08-B25C0A0403E3}.Release|x86.ActiveCfg = Release|Any CPU
564568
{7FC6DD65-0352-4139-8D08-B25C0A0403E3}.Release|x86.Build.0 = Release|Any CPU
569+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
570+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|Any CPU.Build.0 = Debug|Any CPU
571+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|x64.ActiveCfg = Debug|Any CPU
572+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|x64.Build.0 = Debug|Any CPU
573+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|x86.ActiveCfg = Debug|Any CPU
574+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|x86.Build.0 = Debug|Any CPU
575+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|Any CPU.ActiveCfg = Release|Any CPU
576+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|Any CPU.Build.0 = Release|Any CPU
577+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|x64.ActiveCfg = Release|Any CPU
578+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|x64.Build.0 = Release|Any CPU
579+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|x86.ActiveCfg = Release|Any CPU
580+
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|x86.Build.0 = Release|Any CPU
581+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
582+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
583+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|x64.ActiveCfg = Debug|Any CPU
584+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|x64.Build.0 = Debug|Any CPU
585+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|x86.ActiveCfg = Debug|Any CPU
586+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|x86.Build.0 = Debug|Any CPU
587+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
588+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|Any CPU.Build.0 = Release|Any CPU
589+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|x64.ActiveCfg = Release|Any CPU
590+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|x64.Build.0 = Release|Any CPU
591+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|x86.ActiveCfg = Release|Any CPU
592+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|x86.Build.0 = Release|Any CPU
565593
EndGlobalSection
566594

567595
GlobalSection(NestedProjects) = preSolution
@@ -611,5 +639,7 @@ Global
611639
{F8F80477-1EAD-4C5C-A329-CBC0A60C7CAB} = {A566F2D7-F8FE-466A-8306-85F266B7E656}
612640
{A422C742-2CF9-409D-BDAE-15825AB62113} = {A566F2D7-F8FE-466A-8306-85F266B7E656}
613641
{7FC6DD65-0352-4139-8D08-B25C0A0403E3} = {4EAB66F9-C9CB-4E8A-BEE6-A14CD7FDE02F}
642+
{61374D8E-F77C-4A31-AE07-35DAF1847369} = {1CFF5568-8486-475F-81F6-06105C437528}
643+
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
614644
EndGlobalSection
615645
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--suppress MsbuildTargetFrameworkTagInspection -->
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
4+
<PropertyGroup>
5+
<PackageId>AWS.Lambda.Powertools.EventHandler</PackageId>
6+
<Description>Powertools for AWS Lambda (.NET) - Event Handler package.</Description>
7+
<AssemblyName>AWS.Lambda.Powertools.EventHandler</AssemblyName>
8+
<RootNamespace>AWS.Lambda.Powertools.EventHandler</RootNamespace>
9+
<TargetFrameworks>net8.0</TargetFrameworks>
10+
<TargetMultiFramework>false</TargetMultiFramework>
11+
<ImplicitUsings>enable</ImplicitUsings>
12+
<Nullable>enable</Nullable>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Amazon.Lambda.Core" />
17+
</ItemGroup>
18+
19+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace AWS.Lambda.Powertools.EventHandler.AppSyncEvents;
2+
3+
/// <summary>
4+
/// Represents Amazon Cognito User Pools authorization identity for AppSync
5+
/// </summary>
6+
public class AppSyncCognitoIdentity
7+
{
8+
/// <summary>
9+
/// The source IP address of the caller received by AWS AppSync
10+
/// </summary>
11+
public List<string>? SourceIp { get; set; }
12+
13+
/// <summary>
14+
/// The username of the authenticated user
15+
/// </summary>
16+
public string? Username { get; set; }
17+
18+
/// <summary>
19+
/// The UUID of the authenticated user
20+
/// </summary>
21+
public string? Sub { get; set; }
22+
23+
/// <summary>
24+
/// The claims that the user has
25+
/// </summary>
26+
public Dictionary<string, object>? Claims { get; set; }
27+
28+
/// <summary>
29+
/// The default authorization strategy for this caller (ALLOW or DENY)
30+
/// </summary>
31+
public string? DefaultAuthStrategy { get; set; }
32+
33+
/// <summary>
34+
/// List of OIDC groups
35+
/// </summary>
36+
public List<string>? Groups { get; set; }
37+
38+
/// <summary>
39+
/// The token issuer
40+
/// </summary>
41+
public string? Issuer { get; set; }
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace AWS.Lambda.Powertools.EventHandler.AppSyncEvents;
4+
5+
/// <summary>
6+
/// Represents an event from AWS AppSync.
7+
/// </summary>
8+
public class AppSyncEvent
9+
{
10+
/// <summary>
11+
/// Payload data when operation succeeds
12+
/// </summary>
13+
[JsonPropertyName("payload")]
14+
public Dictionary<string, object>? Payload { get; set; }
15+
16+
/// <summary>
17+
/// Error message when operation fails
18+
/// </summary>
19+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
20+
[JsonPropertyName("error")]
21+
public string? Error { get; set; }
22+
23+
/// <summary>
24+
/// Unique identifier for the event
25+
/// This Id is provided by AppSync and needs to be preserved.
26+
/// </summary>
27+
[JsonPropertyName("id")]
28+
public string? Id { get; set; }
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace AWS.Lambda.Powertools.EventHandler.AppSyncEvents;
4+
5+
/// <summary>
6+
/// Represents the operation type for AppSync events.
7+
/// </summary>
8+
[JsonConverter(typeof(JsonStringEnumConverter))]
9+
public enum AppSyncEventsOperation
10+
{
11+
/// <summary>
12+
/// Represents a subscription operation.
13+
/// </summary>
14+
Subscribe,
15+
16+
/// <summary>
17+
/// Represents a publish operation.
18+
/// </summary>
19+
Publish
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace AWS.Lambda.Powertools.EventHandler.AppSyncEvents;
4+
5+
/// <summary>
6+
/// Represents the event payload received from AWS AppSync.
7+
/// </summary>
8+
public class AppSyncEventsRequest
9+
{
10+
/// <summary>
11+
/// An object that contains information about the caller.
12+
/// Returns null for API_KEY authorization.
13+
/// Returns AppSyncIamIdentity for AWS_IAM authorization.
14+
/// Returns AppSyncCognitoIdentity for AMAZON_COGNITO_USER_POOLS authorization.
15+
/// For AWS_LAMBDA authorization, returns the object returned by your Lambda authorizer function.
16+
/// </summary>
17+
/// <remarks>
18+
/// The Identity object type depends on the authorization mode:
19+
/// - For API_KEY: null
20+
/// - For AWS_IAM: <see cref="AppSyncIamIdentity"/>
21+
/// - For AMAZON_COGNITO_USER_POOLS: <see cref="AppSyncCognitoIdentity"/>
22+
/// - For AWS_LAMBDA: <see cref="AppSyncLambdaIdentity"/>
23+
/// - For OPENID_CONNECT: <see cref="AppSyncOidcIdentity"/>
24+
/// </remarks>
25+
public object? Identity { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets information about the data source that originated the event.
29+
/// </summary>
30+
[JsonPropertyName("source")]
31+
public object? Source { get; set; }
32+
33+
/// <summary>
34+
/// Gets or sets information about the HTTP request that triggered the event.
35+
/// </summary>
36+
[JsonPropertyName("request")]
37+
public RequestContext? Request { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets information about the previous state of the data before the operation was executed.
41+
/// </summary>
42+
[JsonPropertyName("prev")]
43+
public object? Prev { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets information about the GraphQL operation being executed.
47+
/// </summary>
48+
[JsonPropertyName("info")]
49+
public Information? Info { get; set; }
50+
51+
/// <summary>
52+
/// Gets or sets additional information that can be passed between Lambda functions during an AppSync pipeline.
53+
/// </summary>
54+
[JsonPropertyName("stash")]
55+
public Dictionary<string, object>? Stash { get; set; }
56+
57+
/// <summary>
58+
/// The error message when the operation fails.
59+
/// </summary>
60+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
61+
[JsonPropertyName("error")]
62+
public string? Error { get; set; }
63+
64+
/// <summary>
65+
/// The list of error message when the operation fails.
66+
/// </summary>
67+
public object[]? OutErrors { get; set; }
68+
69+
/// <summary>
70+
/// The list of events sent.
71+
/// </summary>
72+
[JsonPropertyName("events")]
73+
public AppSyncEvent[]? Events { get; set; }
74+
}

0 commit comments

Comments
 (0)