When using AWS AppSync with lambda data sources you can encounter N+1 query problem.
Basically when you have individual field resolver on your type and your query returns an array of those types you field resolver lambda will be called N times.
AWS introduces BatchInvoking lambdas in resolvers to combat this problem. Here you can read more about the problem and their solution: https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html#advanced-use-case-batching
However, their solution is not working. BatchInvoking lambdas are limited to only 5 events (this is not stated in documentation). It is a slight improvement to the N+1 problem (it makes it N/5+1), but I think it is not enough as more complex queries tend to execute for a very long time and require more lambda invocations.
So my question is how do you deal with this problem? Is there any better solution to this?
From the schema editor in the AWS AppSync console, on the right side, choose Attach Resolver for getPost(id:ID!): Post . Choose your Lambda data source. In the request mapping template section, choose Invoke And Forward Arguments. In the response mapping template section, choose Return Lambda Result.
Testing ResolversIn the AWS AppSync console, go to the Schema page, and choose an existing resolver on the right to edit it. Or, choose Attach to add a new resolver. At the top of the page, choose Select test context, choose Create new context, and then enter a name.
AWS AppSync has support for automatic provisioning and connections with certain data source types. AWS AppSync supports AWS Lambda, Amazon DynamoDB, relational databases (Amazon Aurora Serverless), Amazon OpenSearch Service, and HTTP endpoints as data sources.
Schema files are text files, usually named schema.graphql . You can create this file and submit it to AWS AppSync by using the CLI or navigating to the console and adding the following under the Schema page: schema { } Every schema has this root for processing. This fails to process until you add a root query type.
Until Appsync fixes their issues, we are using an Apollo server as a gateway in ECS to stitch the schemas made with Prisma and invokes lambdas directly where our logic is set.
For your request you can follow up on the feature request in their GitHub repo, which sadly does not have a lot of progress. https://github.com/aws/aws-appsync-community/issues/51
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With