Skip to content

Commit a146de9

Browse files
PankajRawat333Pankaj Rawatankushjain358
authored
Add AWS AppSyncEvent (#1939)
* Initial changes for AppSyncEvent * Added AppSyncEvent class, and respective test cases * Updated README * Update readme * Update Arguments type in event * Update schema * fix review comment * Added Lambda and oidc auth type * Update readme * Added changefile * Added AuthorizerEvent and Result * update changefile and readme * Update JsonProperty attribute * Test case updated * Added new tests, updated readme and incorporated review comments * Updated README * Updated README * fixed code review comments * fixed formatting * Revert warning and remove condition * Added .net8 directive * Remove warning * fixed review comments * fix formatting * Refactor .NET8 and 6 test * Moved AppSync tests to a new prpject * Reverted EventTests file --------- Co-authored-by: Pankaj Rawat <pankajrw@amazon.com> Co-authored-by: Ankush Jain <ankushzn@amazon.com>
1 parent 67b0782 commit a146de9

25 files changed

+1112
-5
lines changed

.autover/autover.json

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@
143143
{
144144
"Name": "Amazon.Lambda.TestTool",
145145
"Path": "Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj"
146+
},
147+
{
148+
"Name": "Amazon.Lambda.AppSyncEvents",
149+
"Path": "Libraries/src/Amazon.Lambda.AppSyncEvents/Amazon.Lambda.AppSyncEvents.csproj"
146150
}
147151
],
148152
"UseCommitsForChangelog": false,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.AppSyncEvents",
5+
"Type": "Major",
6+
"ChangelogMessages": [
7+
"Added AppSyncResolverEvent to support direct lambda resolver"
8+
]
9+
}
10+
]
11+
}

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ The available projects are:
105105
* Amazon.Lambda.SQSEvents
106106
* Amazon.Lambda.TestUtilities
107107
* Amazon.Lambda.TestTool.BlazorTester
108+
* Amazon.Lambda.AppSyncEvents
108109

109110
The possible increment types are:
110111
* Patch

Libraries/Libraries.sln

+19-4
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,21 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestMinimalAPIApp", "test\T
123123
EndProject
124124
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.MQEvents", "src\Amazon.Lambda.MQEvents\Amazon.Lambda.MQEvents.csproj", "{BF85932E-2DFF-41CD-8090-A672468B8FBB}"
125125
EndProject
126-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.LexV2Events", "src\Amazon.Lambda.LexV2Events\Amazon.Lambda.LexV2Events.csproj", "{3C6AABF5-0372-41E0-874F-DF18ECCC7FB6}"
126+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.LexV2Events", "src\Amazon.Lambda.LexV2Events\Amazon.Lambda.LexV2Events.csproj", "{3C6AABF5-0372-41E0-874F-DF18ECCC7FB6}"
127127
EndProject
128-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest", "test\Amazon.Lambda.RuntimeSupport.Tests\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest.csproj", "{0BD83939-458C-4EF5-8663-7098AD1200F2}"
128+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest", "test\Amazon.Lambda.RuntimeSupport.Tests\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest\CustomRuntimeAspNetCoreMinimalApiCustomSerializerTest.csproj", "{0BD83939-458C-4EF5-8663-7098AD1200F2}"
129129
EndProject
130130
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestExecutableServerlessApp", "test\TestExecutableServerlessApp\TestExecutableServerlessApp.csproj", "{DD378063-C54A-44C7-9A6F-32A6A1AE94B3}"
131131
EndProject
132132
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestServerlessApp.NET8", "test\TestServerlessApp.NET8\TestServerlessApp.NET8.csproj", "{7300983D-8FCE-42EA-9B9E-B1C5347D15D8}"
133133
EndProject
134-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnapshotRestore.Registry", "src\SnapshotRestore.Registry\SnapshotRestore.Registry.csproj", "{7261A438-8C1D-47AD-98B0-7678F72E4382}"
134+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnapshotRestore.Registry", "src\SnapshotRestore.Registry\SnapshotRestore.Registry.csproj", "{7261A438-8C1D-47AD-98B0-7678F72E4382}"
135135
EndProject
136-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnapshotRestore.Registry.Tests", "test\SnapshotRestore.Registry.Tests\SnapshotRestore.Registry.Tests.csproj", "{A699E183-D0D4-4F26-A0A7-88DA5607F455}"
136+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnapshotRestore.Registry.Tests", "test\SnapshotRestore.Registry.Tests\SnapshotRestore.Registry.Tests.csproj", "{A699E183-D0D4-4F26-A0A7-88DA5607F455}"
137+
EndProject
138+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.AppSyncEvents", "src\Amazon.Lambda.AppSyncEvents\Amazon.Lambda.AppSyncEvents.csproj", "{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}"
139+
EndProject
140+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventsTests.NET8", "test\EventsTests.NET8\EventsTests.NET8.csproj", "{1FB22337-5D88-4CE7-ADFF-FFD89204F0E9}"
137141
EndProject
138142
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.DynamoDBEvents.SDK.Convertor", "src\Amazon.Lambda.DynamoDBEvents.SDK.Convertor\Amazon.Lambda.DynamoDBEvents.SDK.Convertor.csproj", "{3400F4E9-BA12-4D3D-9BA1-2798AA8D0AFC}"
139143
EndProject
@@ -387,6 +391,14 @@ Global
387391
{D61CBB71-17AB-4EC2-8C6A-70E9D7C60526}.Debug|Any CPU.Build.0 = Debug|Any CPU
388392
{D61CBB71-17AB-4EC2-8C6A-70E9D7C60526}.Release|Any CPU.ActiveCfg = Release|Any CPU
389393
{D61CBB71-17AB-4EC2-8C6A-70E9D7C60526}.Release|Any CPU.Build.0 = Release|Any CPU
394+
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
395+
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}.Debug|Any CPU.Build.0 = Debug|Any CPU
396+
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}.Release|Any CPU.ActiveCfg = Release|Any CPU
397+
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198}.Release|Any CPU.Build.0 = Release|Any CPU
398+
{1FB22337-5D88-4CE7-ADFF-FFD89204F0E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
399+
{1FB22337-5D88-4CE7-ADFF-FFD89204F0E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
400+
{1FB22337-5D88-4CE7-ADFF-FFD89204F0E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
401+
{1FB22337-5D88-4CE7-ADFF-FFD89204F0E9}.Release|Any CPU.Build.0 = Release|Any CPU
390402
EndGlobalSection
391403
GlobalSection(SolutionProperties) = preSolution
392404
HideSolutionNode = FALSE
@@ -456,11 +468,14 @@ Global
456468
{3400F4E9-BA12-4D3D-9BA1-2798AA8D0AFC} = {AAB54E74-20B1-42ED-BC3D-CE9F7BC7FD12}
457469
{074DB940-82BA-47D4-B888-C213D4220A82} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69}
458470
{D61CBB71-17AB-4EC2-8C6A-70E9D7C60526} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69}
471+
{99F39E49-1FD0-4EF5-BF4B-8F2473FB8198} = {AAB54E74-20B1-42ED-BC3D-CE9F7BC7FD12}
472+
{1FB22337-5D88-4CE7-ADFF-FFD89204F0E9} = {1DE4EE60-45BA-4EF7-BE00-B9EB861E4C69}
459473
EndGlobalSection
460474
GlobalSection(ExtensibilityGlobals) = postSolution
461475
SolutionGuid = {503678A4-B8D1-4486-8915-405A3E9CF0EB}
462476
EndGlobalSection
463477
GlobalSection(SharedMSBuildProjectFiles) = preSolution
478+
test\EventsTests.Shared\EventsTests.Shared.projitems*{1fb22337-5d88-4ce7-adff-ffd89204f0e9}*SharedItemsImports = 5
464479
test\EventsTests.Shared\EventsTests.Shared.projitems*{44e9d925-b61d-4234-97b7-61424c963ba6}*SharedItemsImports = 5
465480
test\EventsTests.Shared\EventsTests.Shared.projitems*{a2cb78bb-e54f-48ca-bbfb-9553d27ef23d}*SharedItemsImports = 13
466481
test\EventsTests.Shared\EventsTests.Shared.projitems*{c1bb30d2-3237-4cfc-ba93-627471148ec2}*SharedItemsImports = 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="..\..\..\buildtools\common.props" />
4+
5+
<PropertyGroup>
6+
<Description>Amazon Lambda .NET support - AWS AppSync package.</Description>
7+
<TargetFrameworks>net8.0</TargetFrameworks>
8+
<AssemblyTitle>Amazon.Lambda.AppSyncEvents</AssemblyTitle>
9+
<Version>0.0.1</Version>
10+
<AssemblyName>Amazon.Lambda.AppSyncEvents</AssemblyName>
11+
<PackageId>Amazon.Lambda.AppSyncEvents</PackageId>
12+
<PackageTags>AWS;Amazon;Lambda</PackageTags>
13+
<ImplicitUsings>enable</ImplicitUsings>
14+
</PropertyGroup>
15+
16+
<PropertyGroup>
17+
<WarningsAsErrors>IL2026,IL2067,IL2075</WarningsAsErrors>
18+
<IsTrimmable>true</IsTrimmable>
19+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
20+
</PropertyGroup>
21+
22+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace Amazon.Lambda.AppSyncEvents;
2+
3+
/// <summary>
4+
/// Represents an AWS AppSync authorization event that is sent to a Lambda authorizer
5+
/// for evaluating access permissions to the GraphQL API.
6+
/// </summary>
7+
public class AppSyncAuthorizerEvent
8+
{
9+
/// <summary>
10+
/// Gets or sets the authorization token received from the client request.
11+
/// This token is used to make authorization decisions.
12+
/// </summary>
13+
public string AuthorizationToken { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the headers from the client request.
17+
/// Contains key-value pairs of HTTP header names and their values.
18+
/// </summary>
19+
public Dictionary<string, string> RequestHeaders { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the context information about the AppSync request.
23+
/// Contains metadata about the API and the GraphQL operation being executed.
24+
/// </summary>
25+
public AppSyncRequestContext RequestContext { get; set; }
26+
}
27+
28+
/// <summary>
29+
/// Contains contextual information about the AppSync request being authorized.
30+
/// This class provides details about the API, account, and GraphQL operation.
31+
/// </summary>
32+
public class AppSyncRequestContext
33+
{
34+
/// <summary>
35+
/// Gets or sets the unique identifier of the AppSync API.
36+
/// </summary>
37+
public string ApiId { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the AWS account ID where the AppSync API is deployed.
41+
/// </summary>
42+
public string AccountId { get; set; }
43+
44+
/// <summary>
45+
/// Gets or sets the unique identifier for this specific request.
46+
/// </summary>
47+
public string RequestId { get; set; }
48+
49+
/// <summary>
50+
/// Gets or sets the GraphQL query string containing the operation to be executed.
51+
/// </summary>
52+
public string QueryString { get; set; }
53+
54+
/// <summary>
55+
/// Gets or sets the name of the GraphQL operation to be executed.
56+
/// This corresponds to the operation name in the GraphQL query.
57+
/// </summary>
58+
public string OperationName { get; set; }
59+
60+
/// <summary>
61+
/// Gets or sets the variables passed to the GraphQL operation.
62+
/// Contains key-value pairs of variable names and their values.
63+
/// </summary>
64+
public Dictionary<string, object> Variables { get; set; }
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Text.Json.Serialization;
2+
namespace Amazon.Lambda.AppSyncEvents;
3+
4+
/// <summary>
5+
/// Represents the authorization result returned by a Lambda authorizer to AWS AppSync
6+
/// containing authorization decisions and optional context for the GraphQL API.
7+
/// </summary>
8+
public class AppSyncAuthorizerResult
9+
{
10+
/// <summary>
11+
/// Indicates if the request is authorized
12+
/// </summary>
13+
[JsonPropertyName("isAuthorized")]
14+
public bool IsAuthorized { get; set; }
15+
16+
/// <summary>
17+
/// Custom context to pass to resolvers, only supports key-value pairs.
18+
/// </summary>
19+
[JsonPropertyName("resolverContext")]
20+
public Dictionary<string, string> ResolverContext { get; set; }
21+
22+
/// <summary>
23+
/// List of fields that are denied access
24+
/// </summary>
25+
[JsonPropertyName("deniedFields")]
26+
public IEnumerable<string> DeniedFields { get; set; }
27+
28+
/// <summary>
29+
/// The number of seconds that the response should be cached for
30+
/// </summary>
31+
[JsonPropertyName("ttlOverride")]
32+
public int? TtlOverride { get; set; }
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace Amazon.Lambda.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,47 @@
1+
namespace Amazon.Lambda.AppSyncEvents;
2+
3+
/// <summary>
4+
/// Represents AWS IAM authorization identity for AppSync
5+
/// </summary>
6+
public class AppSyncIamIdentity
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 (IAM user principal)
15+
/// </summary>
16+
public string Username { get; set; }
17+
18+
/// <summary>
19+
/// The AWS account ID of the caller
20+
/// </summary>
21+
public string AccountId { get; set; }
22+
23+
/// <summary>
24+
/// The Amazon Cognito identity pool ID associated with the caller
25+
/// </summary>
26+
public string CognitoIdentityPoolId { get; set; }
27+
28+
/// <summary>
29+
/// The Amazon Cognito identity ID of the caller
30+
/// </summary>
31+
public string CognitoIdentityId { get; set; }
32+
33+
/// <summary>
34+
/// The ARN of the IAM user
35+
/// </summary>
36+
public string UserArn { get; set; }
37+
38+
/// <summary>
39+
/// Either authenticated or unauthenticated based on the identity type
40+
/// </summary>
41+
public string CognitoIdentityAuthType { get; set; }
42+
43+
/// <summary>
44+
/// A comma separated list of external identity provider information used in obtaining the credentials used to sign the request
45+
/// </summary>
46+
public string CognitoIdentityAuthProvider { get; set; }
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Amazon.Lambda.AppSyncEvents;
2+
3+
/// <summary>
4+
/// Represents AWS Lambda authorization identity for AppSync
5+
/// </summary>
6+
public class AppSyncLambdaIdentity
7+
{
8+
/// <summary>
9+
/// Optional context information that will be passed to subsequent resolvers
10+
/// Can contain user information, claims, or any other contextual data
11+
/// </summary>
12+
public Dictionary<string, string> ResolverContext { get; set; }
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Amazon.Lambda.AppSyncEvents;
2+
3+
/// <summary>
4+
/// Represents OpenID Connect authorization identity for AppSync
5+
/// </summary>
6+
public class AppSyncOidcIdentity
7+
{
8+
/// <summary>
9+
/// Claims from the OIDC token as key-value pairs
10+
/// </summary>
11+
public Dictionary<string, object> Claims { get; set; }
12+
13+
/// <summary>
14+
/// The issuer of the OIDC token
15+
/// </summary>
16+
public string Issuer { get; set; }
17+
18+
/// <summary>
19+
/// The UUID of the authenticated user
20+
/// </summary>
21+
public string Sub { get; set; }
22+
}

0 commit comments

Comments
 (0)