Skip to content

Add AWS AppSyncEvent #1939

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 31 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
64d401c
Initial changes for AppSyncEvent
Jan 14, 2025
4335914
Added AppSyncEvent class, and respective test cases
ankushjain358 Jan 21, 2025
f287562
Updated README
ankushjain358 Jan 22, 2025
1bb2045
Update readme
Jan 23, 2025
033f1e8
Update Arguments type in event
Jan 30, 2025
204e17a
Update schema
Feb 5, 2025
87f899a
fix review comment
Feb 17, 2025
8ebea50
Added Lambda and oidc auth type
Mar 7, 2025
24aafb0
Update readme
Mar 7, 2025
634f4a4
Added changefile
Mar 7, 2025
2fdb768
merge from master
Mar 7, 2025
0ad9cd6
Added AuthorizerEvent and Result
Mar 11, 2025
f2af59d
update changefile and readme
Mar 12, 2025
247a2be
Update JsonProperty attribute
Mar 12, 2025
4356b85
Test case updated
Mar 12, 2025
9b8f7ae
Added new tests, updated readme and incorporated review comments
ankushjain358 Mar 23, 2025
f94d588
Updated README
ankushjain358 Mar 23, 2025
5180735
Updated README
ankushjain358 Mar 24, 2025
0708f45
fixed code review comments
Mar 28, 2025
d7cd825
fixed formatting
Mar 28, 2025
1c34513
Revert warning and remove condition
Mar 28, 2025
1530839
Merge branch 'aws:master' into add-aws-appsync-event
PankajRawat333 Mar 28, 2025
06fe270
Added .net8 directive
Mar 28, 2025
308156c
Remove warning
Apr 3, 2025
e37ad36
fixed review comments
Apr 3, 2025
3990078
fix formatting
Apr 3, 2025
25190da
Refactor .NET8 and 6 test
Apr 3, 2025
d2469ca
Moved AppSync tests to a new prpject
ankushjain358 Apr 23, 2025
11723b0
Merge remote-tracking branch 'upstream/dev' into add-aws-appsync-event
ankushjain358 Apr 23, 2025
089f411
Reverted EventTests file
ankushjain358 Apr 23, 2025
e74bda3
Merge remote-tracking branch 'upstream/dev' into add-aws-appsync-event
ankushjain358 Apr 25, 2025
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
4 changes: 4 additions & 0 deletions .autover/autover.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
{
"Name": "Amazon.Lambda.TestTool",
"Path": "Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj"
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fix indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"Name": "Amazon.Lambda.AppSyncEvents",
"Path": "Libraries/src/Amazon.Lambda.AppSyncEvents/Amazon.Lambda.AppSyncEvents.csproj"
}
],
"UseCommitsForChangelog": false,
Expand Down
11 changes: 11 additions & 0 deletions .autover/changes/78ee1265-f50d-434a-b25c-fcb8e9e7a26a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Amazon.Lambda.AppSyncEvents",
"Type": "Major",
"ChangelogMessages": [
"Added AppSyncResolverEvent to support direct lambda resolver"
]
}
]
}
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ The available projects are:
* Amazon.Lambda.SQSEvents
* Amazon.Lambda.TestUtilities
* Amazon.Lambda.TestTool.BlazorTester
* Amazon.Lambda.AppSyncEvents

The possible increment types are:
* Patch
Expand Down
15 changes: 11 additions & 4 deletions Libraries/Libraries.sln
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestMinimalAPIApp", "test\T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.MQEvents", "src\Amazon.Lambda.MQEvents\Amazon.Lambda.MQEvents.csproj", "{BF85932E-2DFF-41CD-8090-A672468B8FBB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.LexV2Events", "src\Amazon.Lambda.LexV2Events\Amazon.Lambda.LexV2Events.csproj", "{3C6AABF5-0372-41E0-874F-DF18ECCC7FB6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.LexV2Events", "src\Amazon.Lambda.LexV2Events\Amazon.Lambda.LexV2Events.csproj", "{3C6AABF5-0372-41E0-874F-DF18ECCC7FB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest", "test\Amazon.Lambda.RuntimeSupport.Tests\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest.csproj", "{0BD83939-458C-4EF5-8663-7098AD1200F2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest", "test\Amazon.Lambda.RuntimeSupport.Tests\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest.csproj", "{0BD83939-458C-4EF5-8663-7098AD1200F2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestExecutableServerlessApp", "test\TestExecutableServerlessApp\TestExecutableServerlessApp.csproj", "{DD378063-C54A-44C7-9A6F-32A6A1AE94B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestServerlessApp.NET8", "test\TestServerlessApp.NET8\TestServerlessApp.NET8.csproj", "{7300983D-8FCE-42EA-9B9E-B1C5347D15D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnapshotRestore.Registry", "src\SnapshotRestore.Registry\SnapshotRestore.Registry.csproj", "{7261A438-8C1D-47AD-98B0-7678F72E4382}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnapshotRestore.Registry", "src\SnapshotRestore.Registry\SnapshotRestore.Registry.csproj", "{7261A438-8C1D-47AD-98B0-7678F72E4382}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnapshotRestore.Registry.Tests", "test\SnapshotRestore.Registry.Tests\SnapshotRestore.Registry.Tests.csproj", "{A699E183-D0D4-4F26-A0A7-88DA5607F455}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnapshotRestore.Registry.Tests", "test\SnapshotRestore.Registry.Tests\SnapshotRestore.Registry.Tests.csproj", "{A699E183-D0D4-4F26-A0A7-88DA5607F455}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.AppSyncEvents", "src\Amazon.Lambda.AppSyncEvents\Amazon.Lambda.AppSyncEvents.csproj", "{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -369,6 +371,10 @@ Global
{A699E183-D0D4-4F26-A0A7-88DA5607F455}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A699E183-D0D4-4F26-A0A7-88DA5607F455}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A699E183-D0D4-4F26-A0A7-88DA5607F455}.Release|Any CPU.Build.0 = Release|Any CPU
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -435,6 +441,7 @@ Global
{7300983D-8FCE-42EA-9B9E-B1C5347D15D8} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69}
{7261A438-8C1D-47AD-98B0-7678F72E4382} = {AAB54E74-20B1-42ED-BC3D-CE9F7BC7FD12}
{A699E183-D0D4-4F26-A0A7-88DA5607F455} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69}
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198} = {AAB54E74-20B1-42ED-BC3D-CE9F7BC7FD12}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {503678A4-B8D1-4486-8915-405A3E9CF0EB}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\buildtools\common.props" />

<PropertyGroup>
<Description>Amazon Lambda .NET Core support - AWS AppSync package.</Description>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we don't need to mention "Core"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

<TargetFrameworks>netstandard2.0;netcoreapp3.1;net8.0</TargetFrameworks>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a new package, we should only target net8.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NET 8 test was written in the 'EventsTests.NET6' project, so I included both net6.0 and net8.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't add a "net6.0" target. For the tests, you could create a 'EventsTests.NET8' project and add the tests there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new project - EventsTests.NET8

<AssemblyTitle>Amazon.Lambda.AppSyncEvents</AssemblyTitle>
<Version>0.0.1</Version>
<AssemblyName>Amazon.Lambda.AppSyncEvents</AssemblyName>
<PackageId>Amazon.Lambda.AppSyncEvents</PackageId>
<PackageTags>AWS;Amazon;Lambda</PackageTags>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the condition if we only target net8.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should only be removed if the targets are net8 and higher. Right now, you are targeting both net6 and net8. You should drop net6.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now target framework is only net8.0

<WarningsAsErrors>IL2026,IL2067,IL2075</WarningsAsErrors>
<IsTrimmable>true</IsTrimmable>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Collections.Generic;
namespace Amazon.Lambda.AppSyncEvents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use top level statement

{
/// <summary>
/// Represents an AWS AppSync authorization event that is sent to a Lambda authorizer
/// for evaluating access permissions to the GraphQL API.
/// </summary>
public class AppSyncAuthorizerEvent
{
/// <summary>
/// Gets or sets the authorization token received from the client request.
/// This token is used to make authorization decisions.
/// </summary>
public string AuthorizationToken { get; set; }

/// <summary>
/// Gets or sets the headers from the client request.
/// Contains key-value pairs of HTTP header names and their values.
/// </summary>
public Dictionary<string, string> RequestHeaders { get; set; }

/// <summary>
/// Gets or sets the context information about the AppSync request.
/// Contains metadata about the API and the GraphQL operation being executed.
/// </summary>
public RequestContext RequestContext { get; set; }
}

/// <summary>
/// Contains contextual information about the AppSync request being authorized.
/// This class provides details about the API, account, and GraphQL operation.
/// </summary>
public class RequestContext
{
/// <summary>
/// Gets or sets the unique identifier of the AppSync API.
/// </summary>
public string ApiId { get; set; }

/// <summary>
/// Gets or sets the AWS account ID where the AppSync API is deployed.
/// </summary>
public string AccountId { get; set; }

/// <summary>
/// Gets or sets the unique identifier for this specific request.
/// </summary>
public string RequestId { get; set; }

/// <summary>
/// Gets or sets the GraphQL query string containing the operation to be executed.
/// </summary>
public string QueryString { get; set; }

/// <summary>
/// Gets or sets the name of the GraphQL operation to be executed.
/// This corresponds to the operation name in the GraphQL query.
/// </summary>
public string OperationName { get; set; }

/// <summary>
/// Gets or sets the variables passed to the GraphQL operation.
/// Contains key-value pairs of variable names and their values.
/// </summary>
public Dictionary<string, object> Variables { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Runtime.Serialization;


namespace Amazon.Lambda.AppSyncEvents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use top level statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

{
/// <summary>
/// Represents the result returned by an AWS AppSync Lambda authorizer.
/// </summary>
[DataContract]
public class AppSyncAuthorizerResult
{
/// <summary>
/// Indicates if the request is authorized
/// </summary>
[DataMember(Name = "isAuthorized")]
#if NETCOREAPP3_1_OR_GREATER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed once we target net8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

[System.Text.Json.Serialization.JsonPropertyName("isAuthorized")]
#endif
public bool IsAuthorized { get; set; }

/// <summary>
/// Custom context to pass to resolvers, only supports key-value pairs.
/// </summary>
[DataMember(Name = "resolverContext")]
#if NETCOREAPP3_1_OR_GREATER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed once we target net8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

[System.Text.Json.Serialization.JsonPropertyName("resolverContext")]
#endif
public Dictionary<string, string> ResolverContext { get; set; }

/// <summary>
/// List of fields that are denied access
/// </summary>
[DataMember(Name = "deniedFields")]
#if NETCOREAPP3_1_OR_GREATER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed once we target net8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

[System.Text.Json.Serialization.JsonPropertyName("deniedFields")]
#endif
public IEnumerable<string> DeniedFields { get; set; }

/// <summary>
/// The number of seconds that the response should be cached for
/// </summary>
[DataMember(Name = "ttlOverride")]
#if NETCOREAPP3_1_OR_GREATER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed once we target net8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

[System.Text.Json.Serialization.JsonPropertyName("ttlOverride")]
#endif
public int? TtlOverride { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Generic;

namespace Amazon.Lambda.AppSyncEvents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use top level statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

{
/// <summary>
/// Represents Amazon Cognito User Pools authorization identity for AppSync
/// </summary>
public class AppSyncCognitoIdentity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PankajRawat333 Please advise on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added AppSyncOidcIdentity and AppSyncLambdaIdentity

{
/// <summary>
/// The source IP address of the caller received by AWS AppSync
/// </summary>
public List<string> SourceIp { get; set; }

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

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

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

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

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

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

}
50 changes: 50 additions & 0 deletions Libraries/src/Amazon.Lambda.AppSyncEvents/AppSyncIamIdentity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections.Generic;

namespace Amazon.Lambda.AppSyncEvents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use top level statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

{
/// <summary>
/// Represents AWS IAM authorization identity for AppSync
/// </summary>
public class AppSyncIamIdentity
{
/// <summary>
/// The source IP address of the caller received by AWS AppSync
/// </summary>
public List<string> SourceIp { get; set; }

/// <summary>
/// The username of the authenticated user (IAM user principal)
/// </summary>
public string Username { get; set; }

/// <summary>
/// The AWS account ID of the caller
/// </summary>
public string AccountId { get; set; }

/// <summary>
/// The Amazon Cognito identity pool ID associated with the caller
/// </summary>
public string CognitoIdentityPoolId { get; set; }

/// <summary>
/// The Amazon Cognito identity ID of the caller
/// </summary>
public string CognitoIdentityId { get; set; }

/// <summary>
/// The ARN of the IAM user
/// </summary>
public string UserArn { get; set; }

/// <summary>
/// Either authenticated or unauthenticated based on the identity type
/// </summary>
public string CognitoIdentityAuthType { get; set; }

/// <summary>
/// A comma separated list of external identity provider information used in obtaining the credentials used to sign the request
/// </summary>
public string CognitoIdentityAuthProvider { get; set; }
}
}
16 changes: 16 additions & 0 deletions Libraries/src/Amazon.Lambda.AppSyncEvents/AppSyncLambdaIdentity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;

namespace Amazon.Lambda.AppSyncEvents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use top level statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

{
/// <summary>
/// Represents AWS LAMBDA authorization identity for AppSync
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why is "LAMBDA" all caps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

/// </summary>
public class AppSyncLambdaIdentity
{
/// <summary>
/// Optional context information that will be passed to subsequent resolvers
/// Can contain user information, claims, or any other contextual data
/// </summary>
public Dictionary<string, string> ResolverContext { get; set; }
}
}
25 changes: 25 additions & 0 deletions Libraries/src/Amazon.Lambda.AppSyncEvents/AppSyncOidcIdentity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;

namespace Amazon.Lambda.AppSyncEvents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use top level statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

{
/// <summary>
/// Represents OPENID CONNECT authorization identity for AppSync
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why is "OPENID CONNECT" all caps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

/// </summary>
public class AppSyncOidcIdentity
{
/// <summary>
/// Claims from the OIDC token as key-value pairs
/// </summary>
public Dictionary<string, object> Claims { get; set; }

/// <summary>
/// The issuer of the OIDC token
/// </summary>
public string Issuer { get; set; }

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