It seems there is a bug in AWS CodePipelines and/or CDK Pipelines specifically which means that the synthesised CloudFormation assets cannot be deployed in the Assets stage because of the following error:
Template format error: JSON not well-formed. (line 1135, column 4) (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: XXXXXXXX; Proxy: null)
But the CloudFormation can be deployed from the local machine using CDK Deploy, bypassing the CodePipeline which suggest the synthesised CloudFormation template is fine. It seems this happens when the CloudFormation template gets too big. It can sometimes be resolved by breaking up the project into multiple stacks. However when you have an AppSync API for example it becomes impractical to break this up. Has anyone experience this issue and found a work around? There is a related github issue but it appears to have gone quiet.
A workaround for this problem seems to be to break up the AppSync stack so that the schema and main API resource are defined in one stack and all the resolvers are defined in one or more different stacks which import the API by id, which splits the CloudFormation templates so that CodePipeline can deploy them. This works but it seems hacky and presumably is not intended. Any better ideas would be welcome.
UPDATE: AWS fixed this issue.