I have an AppSync api created with AWS Amplify. The api has a mutation named createSpeaker which is connected to a pipeline resolver. Amplify have created 4 AppSync functions that is triggered by the resolver.
I want to modify this resolver to add an extra appSync function that is triggered when a user calls the createSpeaker mutation. This new function is supposed to handle logic that automatically creates logs in a sepparate db.
I am stuck on the step where I am trying to add the new AppSync function to the resolver pipeline, because I can't figure out how to import the existing pipeline resolver into CDK.
Do anyone know how to do this?
In a new CDK app I am importing the API
/** importing the existing api */
const api = appsync.GraphqlApi.fromGraphqlApiAttributes(this, 'api', {
graphqlApiId: props.appSyncId,
});
/** adding a lambda fn created earlier in this code as data source */
const lambdaDataSource = api.addLambdaDataSource(props.appName + ' - ' + props.appEnv + '-lambdaLoggerDataSource', props.createLoggLambdaFn);
/**
* creating a new Appsync fn with js as runtime, that will invoke the lambda function (which is supposed to handle the logic)
* I want to connect this appSync fn to other resolvers, so that I can log data to DynamoDB
*/
const appSyncFunction = new appsync.AppsyncFunction(this, props.appName + ' - ' + props.appEnv + '-CreateLoggResolverFn', {
api: api,
runtime: appsync.FunctionRuntime.JS_1_0_0,
dataSource: lambdaDataSource,
name: props.appName + ' - ' + props.appEnv + '-CreateLoggResolverFn',
code: appsync.Code.fromAsset('lib/appsync/resolver'),
description: 'This function should be part of other resolvers to logg data to dynamoDB',
});
/** Next step, where I am stuck, is how to import the resolver from the api and add appSyncFunction to it */
I have already successfully created this logic through clicking in the console, but I want to automate this when creating new enviroment.
In the end I want to connect all the mutations in the app to create this logs. The logs are ment as both a security feature and a practical feature (readable queryable logs). For now this is a separate CDK app, but I will also add this as part of the Amplify add custom feature.