
const lambdaWithStash = `
#set($ctx.stash.newId = $util.autoId())
{"version": "2017-02-28", "operation": "Invoke", "payload": $util.toJson($ctx)}
`
const passThrough = `$util.toJson($ctx.result)`
export const resolverDefaults = {
requestMappingTemplate: Appsync.MappingTemplate.fromString(lambdaWithStash),
responseMappingTemplate: Appsync.MappingTemplate.fromString(passThrough),
}
// this == CDK.Stack
new Appsync.Resolver(this, 'pipeline', {
...resolverDefaults,
api: Graphql, // Appsync.GraphQLApi
typeName: 'Conversation',
fieldName: 'messages',
pipelineConfig: {
functions: ['lambda1', 'lambda2'] // valid lambdas on my Lambda console
}
})
see screnshot
I'm passing a valid, as per cdk types, pipelineConfig but it shows as undefined in my cdk synth output, causing deploy to fail even though my cdk code looks correct
This is :bug: Bug Report
Yeah looks like we are not forwarding pipelineConfig from the L2 to CfnResolver.
https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-appsync/lib/graphqlapi.ts#L1061
imo, we should remove some of the unnecessary information from the pipelineConfig arg as well and make it type Array<string> wrapping it in { functions: } when forwarding to the CfnResolver.
@MrArnoldPalmer what do you think is a reasonable eta on this? no pipeline resolvers means using CDK for Appsync is only a partial solution.
@iamtheworstdev a PR has been submitted but stalled out for now. @Thomazella do you plan on continuing or should we take this over to close it out?
Please take it over. Seems pretty simple but I'm terribly busy lately 馃檹
@iamtheworstdev feel free to jump in if you want to add some tests and try to get this resolved. Otherwise I'll add it to my list but its a long one at the moment 馃槈
@MrArnoldPalmer assume I'm not, because it's not just a clever moniker but you probably don't want me writing the code. but I think my work around for avoid pipelines just reached the end of its useful life so I may. I'll comment back in here if I start any work.
Just hit this issue myself today. Took me a while to realise that the pipeline config just wasn't being populated 馃槄 Any chance this issue could get some love. We're realising more and more how powerful AppSync is and these last few bits polish in CDK will really improve the dev experience.
Any update on the same ? seems like a bad bug, would be great if you guys can fix it. I am currently blocked on the same
Hi @alextriaca @vengadanathan I'll start working on this today, my goal is to complete it and merge by Thursday.
For future reference, please add a 馃憤 to the issues that you are stuck on that way they can get sorted to the top :)
I believe the work around to this pipeline would be to create multiple resolvers as follows.
const api = new GraphQLApi(...);
const function1 = new Lambda(...);
const function2 = new Lambda(...);
const lambda1DS = api.addLambdaDataSource('DS1', 'function1', function1);
const lambda2DS = api.addLambdaDataSource('DS2', 'function2', function2);
lambda1DS.createResolver({
typeName: [TYPE],
fieldName: [FIELD],
requestMappingTemplate: [REQUEST],
responseMappingTemplate: [RESPONSE],
});
lambda2DS.createResolver({
typeName: [TYPE],
fieldName: [FIELD],
requestMappingTemplate: [REQUEST],
responseMappingTemplate: [RESPONSE],
});
specifically making two different data sources and make separate resolvers for each of them.
Okay I think I found the root of the confusion.
The Function that can be added to the pipelineConfig is not a Lambda Function. Instead, it is AppSync::Function.
See documentation on pipelineConfig here.
See documentation on functionConfiguration here.
See documentation on appsync:CreateFunction here.
If you want to use Lambda Functions, I suggest using the addLambdaDataSource and createResolver method outlined above.
That being said, CDK doesn't have implementation for AppSync Function so I will close this issue and opening #9092 for a feature request for AppSync function creation.
Most helpful comment
Okay I think I found the root of the confusion.
The
Functionthat can be added to thepipelineConfigis not aLambda Function. Instead, it isAppSync::Function.See documentation on
pipelineConfighere.See documentation on
functionConfigurationhere.See documentation on
appsync:CreateFunctionhere.If you want to use
Lambda Functions, I suggest using theaddLambdaDataSourceandcreateResolvermethod outlined above.That being said, CDK doesn't have implementation for AppSync Function so I will close this issue and opening #9092 for a feature request for AppSync function creation.