-
Notifications
You must be signed in to change notification settings - Fork 499
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
Add AWS AppSyncEvent #1939
Changes from 11 commits
64d401c
4335914
f287562
1bb2045
033f1e8
204e17a
87f899a
8ebea50
24aafb0
634f4a4
2fdb768
0ad9cd6
f2af59d
247a2be
4356b85
9b8f7ae
f94d588
5180735
0708f45
d7cd825
1c34513
1530839
06fe270
308156c
e37ad36
3990078
25190da
d2469ca
11723b0
089f411
e74bda3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "Projects": [ | ||
| { | ||
| "Name": "Amazon.Lambda.AppSyncEvents", | ||
| "Type": "Patch", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The increment type should have been
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I was asking to validate if validate if
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@philasmar Please review comment #1939 (comment). Should we be specifying version in |
||
| "ChangelogMessages": [ | ||
| "Added AppSyncResolverEvent to support direct lambda resolver" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| 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> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we don't need to mention "Core"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
| <TargetFrameworks>netstandard2.0;netcoreapp3.1;net8.0</TargetFrameworks> | ||
| <AssemblyTitle>Amazon.Lambda.AppSyncEvents</AssemblyTitle> | ||
| <Version>1.0.0</Version> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure if we should specify version when using 1st
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should specify a version below 1.0.0, like 0.0.1 and then use the increment type
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @philasmar Help me to understand your comment. My current
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PankajRawat333 Which
Make sure to delete the old change file if you decide to create a new one. From our end, once the PR is merged in, we will create a release which will automatically run:
This will look at the available
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also please add the new project in this section https://github.com/aws/aws-lambda-dotnet/blob/master/CONTRIBUTING.md#adding-a-change-file-to-your-contribution-branch
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @philasmar, Now created new changefile with increment-type |
||
| <AssemblyName>Amazon.Lambda.AppSyncEvents</AssemblyName> | ||
| <PackageId>Amazon.Lambda.AppSyncEvents</PackageId> | ||
| <PackageTags>AWS;Amazon;Lambda</PackageTags> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the condition if we only target net8.0
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,46 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Amazon.Lambda.AppSyncEvents | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use top level statement
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we didn't implement
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PankajRawat333 Please advise on this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| { | ||
| /// <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; } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Amazon.Lambda.AppSyncEvents | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use top level statement
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Amazon.Lambda.AppSyncEvents | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use top level statement
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| { | ||
| /// <summary> | ||
| /// Represents AWS LAMBDA authorization identity for AppSync | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why is "LAMBDA" all caps?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, object> ResolverContext { get; set; } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Amazon.Lambda.AppSyncEvents | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use top level statement
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| { | ||
| /// <summary> | ||
| /// Represents OPENID CONNECT authorization identity for AppSync | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why is "OPENID CONNECT" all caps?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Amazon.Lambda.AppSyncEvents | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use top level statement
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| { | ||
| /// <summary> | ||
| /// Represents the event payload received from AWS AppSync. | ||
| /// </summary> | ||
| public class AppSyncResolverEvent<TArguments> | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the input arguments for the GraphQL operation. | ||
| /// </summary> | ||
| public TArguments Arguments { get; set; } | ||
|
|
||
| /// <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: Dynamic object returned by Lambda authorizer | ||
| /// </remarks> | ||
| public object Identity { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets information about the data source that originated the event. | ||
| /// </summary> | ||
| public object Source { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets information about the HTTP request that triggered the event. | ||
| /// </summary> | ||
| public RequestContext Request { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets information about the previous state of the data before the operation was executed. | ||
| /// </summary> | ||
| public object Prev { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets information about the GraphQL operation being executed. | ||
| /// </summary> | ||
| public Information Info { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets additional information that can be passed between Lambda functions during an AppSync pipeline. | ||
| /// </summary> | ||
| public Dictionary<string, object> Stash { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Represents information about the HTTP request that triggered the event. | ||
| /// </summary> | ||
| public class RequestContext | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the headers of the HTTP request. | ||
| /// </summary> | ||
| public Dictionary<string, string> Headers { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the domain name associated with the request. | ||
| /// </summary> | ||
| public string DomainName { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents information about the GraphQL operation being executed. | ||
| /// </summary> | ||
| public class Information | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the name of the GraphQL field being executed. | ||
| /// </summary> | ||
| public string FieldName { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a list of fields being selected in the GraphQL operation. | ||
| /// </summary> | ||
| public List<string> SelectionSetList { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the GraphQL selection set for the operation. | ||
| /// </summary> | ||
| public string SelectionSetGraphQL { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the variables passed to the GraphQL operation. | ||
| /// </summary> | ||
| public Dictionary<string, object> Variables { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the parent type name for the GraphQL operation. | ||
| /// </summary> | ||
| public string ParentTypeName { get; set; } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Amazon.Lambda.AppSyncEvents | ||
|
|
||
| This package contains classes that can be used as input types for Lambda functions that process AppSync events. | ||
|
|
||
| # Sample Function | ||
|
|
||
| The following is a sample class and Lambda function that receives AppSync resolver event record data as an `appSyncResolverEvent` and logs some of the incoming event data. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) | ||
|
|
||
| ```csharp | ||
| public void Handler(AppSyncResolverEvent<Dictionary<string, object>> appSyncResolverEvent, ILambdaContext context) | ||
| { | ||
| foreach (var item in appSyncResolverEvent.Arguments) | ||
| { | ||
| Console.WriteLine($"AppSync request key - {item.Key}."); | ||
| } | ||
|
|
||
| if (appSyncResolverEvent.Identity != null) | ||
| { | ||
| // Create an instance of the serializer | ||
| var lambdaSerializer = new DefaultLambdaJsonSerializer(); | ||
|
|
||
| using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(appSyncResolverEvent.Identity.ToString()!))) | ||
| { | ||
| // When using AMAZON_COGNITO_USER_POOLS authorization | ||
| var cognitoIdentity = lambdaSerializer.Deserialize<AppSyncCognitoIdentity>(stream); | ||
|
|
||
| // When using AWS_IAM authorization | ||
| var iamIdentity = lambdaSerializer.Deserialize<AppSyncIamIdentity>(stream); | ||
|
|
||
| // When using AWS_LAMBDA authorization | ||
| var lambdaIdentity = lambdaSerializer.Deserialize<AppSyncLambdaIdentity>(stream); | ||
|
|
||
| // When using OPENID_CONNECT authorization | ||
| var oidcIdentity = lambdaSerializer.Deserialize<AppSyncOidcIdentity>(stream); | ||
| } | ||
| } | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fix indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed