Choosing between direct data source access and proxying via a Lambda data source
With Amazon AppSync and the APPSYNC_JS
runtime, you can write your own code that implements your
custom business logic by using Amazon AppSync functions to access your data sources. This makes it easy for you
to directly interact with data sources like Amazon DynamoDB, Aurora Serverless, OpenSearch Service, HTTP APIs, and
other Amazon services without having to deploy additional computational services or infrastructure.
Amazon AppSync also makes it easy to interact with an Amazon Lambda function by configuring a Lambda data source.
Lambda data sources allow you to run complex business logic using Amazon Lambda’s full set capabilities to resolve a
GraphQL request. In most cases, an Amazon AppSync function directly connected to its target data source will
provide all of the functionality you need. In situations where you need to implement complex business logic
that is not supported by the APPSYNC_JS
runtime, you can use a Lambda data source as a proxy to
interact with your target data source.
Direct data source integration | Lambda data source as a proxy | |
Use case | Amazon AppSync functions interact directly with API data sources. | Amazon AppSync functions call Lambdas that interact with API data sources. |
Runtime | APPSYNC_JS (JavaScript) |
Any supported Lambda runtime |
Maximum size of code | 32,000 characters per Amazon AppSync function | 50 MB (zipped, for direct upload) per Lambda |
External modules | Limited - APPSYNC_JS supported features only | Yes |
Call any Amazon service | Yes - Using Amazon AppSync HTTP datasource | Yes - Using Amazon SDK |
Access to the request header | Yes | Yes |
Network access | No | Yes |
File system access | No | Yes |
Logging and metrics | Yes | Yes |
Build and test entirely within AppSync | Yes | No |
Cold start | No | No - With provisioned concurrency |
Auto-scaling | Yes - transparently by Amazon AppSync | Yes - As configured in Lambda |
Pricing | No additional charge | Charged for Lambda usage |
Amazon AppSync functions that integrate directly with their target data source are ideal for use cases like the following:
-
Interacting with Amazon DynamoDB, Aurora Serverless, and OpenSearch Service
-
Interacting with HTTP APIs and passing incoming headers
-
Interacting with Amazon services using HTTP data sources (with Amazon AppSync automatically signing requests with the provided data source role)
-
Implementing access control before accessing data sources
-
Implementing the filtering of retrieved data prior to fulfilling a request
-
Implementing simple orchestration with sequential execution of Amazon AppSync functions in a resolver pipeline
-
Controlling caching and subscription connections in queries and mutations.
Amazon AppSync functions that use a Lambda data source as a proxy are ideal for use cases like the following:
-
Using a language other than JavaScript or Velocity Template Language (VTL)
-
Adjusting and controlling CPU or memory to optimize performance
-
Importing third-party libraries or requiring unsupported features in
APPSYNC_JS
-
Making multiple network requests and/or getting file system access to fulfill a query
-
Batching requests using batching configuration.