-
Notifications
You must be signed in to change notification settings - Fork 76
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
feat(function-transformer): add support for event invocation types (async lambda) #2864
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ync-lambda chore: merge main to feature/async-lambda
atierian
changed the title
Feature/async lambda
feat(function-transformer): add support for event invocation types (async lambda)
Sep 11, 2024
chore: merge main into feature/async-lambda
palpatim
reviewed
Sep 11, 2024
...lify-graphql-function-transformer/src/__tests__/amplify-graphql-function-transformer.test.ts
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Outdated
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Outdated
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Outdated
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Outdated
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Outdated
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Show resolved
Hide resolved
phani-srikar
previously approved these changes
Sep 11, 2024
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Show resolved
Hide resolved
packages/amplify-graphql-function-transformer/src/graphql-function-transformer.ts
Show resolved
Hide resolved
6 tasks
sundersc
approved these changes
Sep 12, 2024
palpatim
approved these changes
Sep 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes already reviewed in
Description of changes
Adds support for AppSync asynchronous Lambda function invocations via the
@function
directive.API Changes
Callouts
appendError
vserror
The response mapping template for
Event
invocation types usesutil.appendError
rather thanutil.error
used byRequestResponse
(default) invocation types.util.error
has always been the behavior of the@function
directive. I was unable to find any justification for the decision in the original PR:util.error
immediately exits preventing any further execution in the response (also request but n/a here) mapping template and subsequent resolvers in the same pipeline. This is reasonable in the context of single function resolvers, but is unnecessarily constraining in a multi-function pipeline -- usingutil.appendError
could¹ allow the subsequent Lambda function to make a handling decision for the previous error based on business logic.Changing this behavior for existing
RequestResponse
(default)@function
directives would be a breaking change. However, we have an opportunity to move in a more flexible direction for the newly introducedEvent
based@function
directives. We're usingutil.appendError
in the response mapping template ofEvent
@function
directives for two reasons:EventInvocationResponse
regardless of whether the Lambda function execution failed or not.For comparison, if
Event
based@function
directives usedutil.error
, this would be the failure response:¹ This would require passing
ctx.error
in the Lambda invocation payload; this is not done today and is not included in this PR.While we're on the topic, I'm going to document the behavior of
util.error
andutil.appendError
in pipeline resolvers for future reference.util.error
immediately exits, returning the error and only the error to the caller. Neither subsequent lines in the request/response mapping template nor subsequent resolvers in a pipeline are executed afterutil.error
util.appendError
continues execution and returns the appended error in theerrors
block of the request.util.appendError
, then callingutil.error
results in the appended error being excluded in theerrors
block -- only the error passed toutil.error
is returned in theerrors
block.Response Types
Using
@function(name: 'name', invocationType: Event)
requires that the response type of that field isEventInvocationResponse
, which must be explicitly defined in the schema as:This applies when the
Event
invocation type@function
directive is the final@function
directive defined on that field. For example:But not when a 'RequestResponse' invocation is the final
@function
directive. This is fine:Constraints
Event
invocation type@function
directives can only be used onMutation
orQuery
fields. This is is more constraining thanRequestResponse
(default) invocation types.CDK / CloudFormation Parameters Changed
Issue #, if available
Description of how you validated changes
Note: This PR is into the
feature/async-lambda
branch where a tagged release will be cut. A full E2E test run will happen prior to merging this tomain
.Checklist
yarn test
passesRelevant documentation is changed or added (and PR referenced)New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policiesAny CDK or CloudFormation parameter changes are called out explicitlyBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.