AWSLambdaDataSource
Use AWS Lambda as an Apollo DataSources.
Based on SQLDataSource.
Installation
To install AWSLambdaDataSource:
npm i apollo-datasource-lambda
Or if you prefer yarn
yarn add apollo-datasource-lambda
Usage
invoke(payload, ttl = 5)
:
payload
: Buffer.from('...') || 'STRING_VALUE' Strings will be Base-64 encoded on your behalf
ttl
: the number of seconds to retain the data in the cache (DEFAULT: 5)
Configure Apollo:
const AWSLambdaDataSource = ; const lambdaAwesome = region: "us-west-2" FunctionName: "my-awesome-function" ; const server = typeDefs resolvers cache context lambdaAwesome ;
Use:
const TTL_ONE_MINUTE = 60; static async { const event = question: "What is the meaning of life?" ; // Returns Promise as if you called AWS.Lambda().invoke().promise() const response = await dataSourceslambdaAwesome; return response"Payload"; } moduleexports = Awesome;
Configuration
If no cache is provided in your Apollo server configuration, AWSLambdaDataSource falls back to the same InMemoryLRUCache leveraged by Apollo's RESTDataSource.
Instance Variables
context
The context from your Apollo server.
lambda
The AWS.Lambda
instance.