Skip to content

chore: Feature/appsync events #858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
714 changes: 714 additions & 0 deletions docs/core/event_handler/appsync_events.md

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions libraries/AWS.Lambda.Powertools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metrics", "Metrics", "{A566
EndProject
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}"
EndProject
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}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -562,6 +566,30 @@ Global
{7FC6DD65-0352-4139-8D08-B25C0A0403E3}.Release|x64.Build.0 = Release|Any CPU
{7FC6DD65-0352-4139-8D08-B25C0A0403E3}.Release|x86.ActiveCfg = Release|Any CPU
{7FC6DD65-0352-4139-8D08-B25C0A0403E3}.Release|x86.Build.0 = Release|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|x64.ActiveCfg = Debug|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|x64.Build.0 = Debug|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|x86.ActiveCfg = Debug|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Debug|x86.Build.0 = Debug|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|Any CPU.Build.0 = Release|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|x64.ActiveCfg = Release|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|x64.Build.0 = Release|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|x86.ActiveCfg = Release|Any CPU
{61374D8E-F77C-4A31-AE07-35DAF1847369}.Release|x86.Build.0 = Release|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|x64.ActiveCfg = Debug|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|x64.Build.0 = Debug|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|x86.ActiveCfg = Debug|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Debug|x86.Build.0 = Debug|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|Any CPU.Build.0 = Release|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|x64.ActiveCfg = Release|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|x64.Build.0 = Release|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|x86.ActiveCfg = Release|Any CPU
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection

GlobalSection(NestedProjects) = preSolution
Expand Down Expand Up @@ -611,5 +639,7 @@ Global
{F8F80477-1EAD-4C5C-A329-CBC0A60C7CAB} = {A566F2D7-F8FE-466A-8306-85F266B7E656}
{A422C742-2CF9-409D-BDAE-15825AB62113} = {A566F2D7-F8FE-466A-8306-85F266B7E656}
{7FC6DD65-0352-4139-8D08-B25C0A0403E3} = {4EAB66F9-C9CB-4E8A-BEE6-A14CD7FDE02F}
{61374D8E-F77C-4A31-AE07-35DAF1847369} = {1CFF5568-8486-475F-81F6-06105C437528}
{F4B8D5AF-D3CA-4910-A14D-E5BAEF0FD1DE} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--suppress MsbuildTargetFrameworkTagInspection -->
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>AWS.Lambda.Powertools.EventHandler</PackageId>
<Description>Powertools for AWS Lambda (.NET) - Event Handler package.</Description>
<AssemblyName>AWS.Lambda.Powertools.EventHandler</AssemblyName>
<RootNamespace>AWS.Lambda.Powertools.EventHandler</RootNamespace>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetMultiFramework>false</TargetMultiFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace AWS.Lambda.Powertools.EventHandler.AppSyncEvents;

/// <summary>
/// Represents Amazon Cognito User Pools authorization identity for AppSync
/// </summary>
public class AppSyncCognitoIdentity
{
/// <summary>
/// The source IP address of the caller received by AWS AppSync
/// </summary>
public List<string>? SourceIp { get; set; }

Check warning on line 11 in libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs

View check run for this annotation

Codecov / codecov/patch

libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs#L11

Added line #L11 was not covered by tests

/// <summary>
/// The username of the authenticated user
/// </summary>
public string? Username { get; set; }

Check warning on line 16 in libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs

View check run for this annotation

Codecov / codecov/patch

libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs#L16

Added line #L16 was not covered by tests

/// <summary>
/// The UUID of the authenticated user
/// </summary>
public string? Sub { get; set; }

Check warning on line 21 in libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs

View check run for this annotation

Codecov / codecov/patch

libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs#L21

Added line #L21 was not covered by tests

/// <summary>
/// The claims that the user has
/// </summary>
public Dictionary<string, object>? Claims { get; set; }

Check warning on line 26 in libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs

View check run for this annotation

Codecov / codecov/patch

libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs#L26

Added line #L26 was not covered by tests

/// <summary>
/// The default authorization strategy for this caller (ALLOW or DENY)
/// </summary>
public string? DefaultAuthStrategy { get; set; }

Check warning on line 31 in libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs

View check run for this annotation

Codecov / codecov/patch

libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs#L31

Added line #L31 was not covered by tests

/// <summary>
/// List of OIDC groups
/// </summary>
public List<string>? Groups { get; set; }

Check warning on line 36 in libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs

View check run for this annotation

Codecov / codecov/patch

libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs#L36

Added line #L36 was not covered by tests

/// <summary>
/// The token issuer
/// </summary>
public string? Issuer { get; set; }

Check warning on line 41 in libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs

View check run for this annotation

Codecov / codecov/patch

libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncCognitoIdentity.cs#L41

Added line #L41 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Text.Json.Serialization;

namespace AWS.Lambda.Powertools.EventHandler.AppSyncEvents;

/// <summary>
/// Represents an event from AWS AppSync.
/// </summary>
public class AppSyncEvent
{
/// <summary>
/// Payload data when operation succeeds
/// </summary>
[JsonPropertyName("payload")]
public Dictionary<string, object>? Payload { get; set; }

/// <summary>
/// Error message when operation fails
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("error")]
public string? Error { get; set; }

/// <summary>
/// Unique identifier for the event
/// This Id is provided by AppSync and needs to be preserved.
/// </summary>
[JsonPropertyName("id")]
public string? Id { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;

namespace AWS.Lambda.Powertools.EventHandler.AppSyncEvents;

/// <summary>
/// Represents the operation type for AppSync events.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum AppSyncEventsOperation
{
/// <summary>
/// Represents a subscription operation.
/// </summary>
Subscribe,

/// <summary>
/// Represents a publish operation.
/// </summary>
Publish
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Text.Json.Serialization;

namespace AWS.Lambda.Powertools.EventHandler.AppSyncEvents;

/// <summary>
/// Represents the event payload received from AWS AppSync.
/// </summary>
public class AppSyncEventsRequest
{
/// <summary>
/// An object that contains information about the caller.
/// Returns null for API_KEY authorization.
/// Returns AppSyncIamIdentity for AWS_IAM authorization.
/// Returns AppSyncCognitoIdentity for AMAZON_COGNITO_USER_POOLS authorization.
/// For AWS_LAMBDA authorization, returns the object returned by your Lambda authorizer function.
/// </summary>
/// <remarks>
/// The Identity object type depends on the authorization mode:
/// - For API_KEY: null
/// - For AWS_IAM: <see cref="AppSyncIamIdentity"/>
/// - For AMAZON_COGNITO_USER_POOLS: <see cref="AppSyncCognitoIdentity"/>
/// - For AWS_LAMBDA: <see cref="AppSyncLambdaIdentity"/>
/// - For OPENID_CONNECT: <see cref="AppSyncOidcIdentity"/>
/// </remarks>
public object? Identity { get; set; }

/// <summary>
/// Gets or sets information about the data source that originated the event.
/// </summary>
[JsonPropertyName("source")]
public object? Source { get; set; }

Check warning on line 31 in libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncEventsRequest.cs

View check run for this annotation

Codecov / codecov/patch

libraries/src/AWS.Lambda.Powertools.EventHandler/AppSyncEvents/AppSyncEventsRequest.cs#L31

Added line #L31 was not covered by tests

/// <summary>
/// Gets or sets information about the HTTP request that triggered the event.
/// </summary>
[JsonPropertyName("request")]
public RequestContext? Request { get; set; }

/// <summary>
/// Gets or sets information about the previous state of the data before the operation was executed.
/// </summary>
[JsonPropertyName("prev")]
public object? Prev { get; set; }

/// <summary>
/// Gets or sets information about the GraphQL operation being executed.
/// </summary>
[JsonPropertyName("info")]
public Information? Info { get; set; }

/// <summary>
/// Gets or sets additional information that can be passed between Lambda functions during an AppSync pipeline.
/// </summary>
[JsonPropertyName("stash")]
public Dictionary<string, object>? Stash { get; set; }

/// <summary>
/// The error message when the operation fails.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("error")]
public string? Error { get; set; }

/// <summary>
/// The list of error message when the operation fails.
/// </summary>
public object[]? OutErrors { get; set; }

/// <summary>
/// The list of events sent.
/// </summary>
[JsonPropertyName("events")]
public AppSyncEvent[]? Events { get; set; }
}
Loading
Loading