question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make AppSync and MappingTemplate L2-constructs work with CodePipeline deployments

See original GitHub issue

Deploy an AppSync API with a schema definition file and resolver mapping templates in a CodePipeline using CloudFormation actions.

Use Case

I want to deploy an AppSync API in a CodePipeline and I don’t want to inline the schema into the CDK code because I want to generate model classes from it.

Currently, the schema definition must be provided either as a string or as an asset (not yet supported by CloudFormations actions). It is not possible to provide S3-locations without redefining the current L2-construct.

CDK source code:

https://github.com/aws/aws-cdk/blob/bf0113b01bb1c5548d87391b01670fca12636609/packages/%40aws-cdk/aws-appsync/lib/graphqlapi.ts#L236-L243

Proposed Solution

Provide S3-locations of the schema definition file and any resolver mapping templates to the synthesized template using CloudFormation parameters, similar to CfnParametersCode (see example here).

Since the number of mapping templates can be very high, a solution that requires only one parameter representing the S3-folder containing the mapping templates would be useful.

Creating an AppSync API and mapping templates could look like:

const schema = new cdk.CfnParameter(this, 'GraphQLSchemaS3Location');
const resolversDir = new cdk.CfnParameter(this, 'GraphQLMappingTemplatesS3Location');

const api = new appsync.GraphQLApi(this, 'GraphQLApi', {
  name: `GraphQLApi`,
  schemaDefinitionLocation: schema,
});

someDataSource.createQueryResolver({
  field: 'getHello',
  requestTemplate:  appsync.MappingTemplate.fromS3Location(resolversDir, 'getHello-request-mapping-template.vtl'),
  responseTemplate: appsync.MappingTemplate.fromS3Location(resolversDir, 'getHello-response-mapping-template.vtl'),
});

Other

Related question on Gitter.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
BryanPan342commented, Jul 21, 2020

Ah I see. I think this discussion would be great to keep open.

I think if we could change the issue name/message to reflect our discussion that would be fantastic!

1reaction
asterikxcommented, Jul 17, 2020

@BryanPan342 Thanks for you response.

Both would be all would be strings as that’s what the CloudFormation props take…

I don’t completely understand. Could you maybe sketch your solution? My idea was that the CDK would take care of uploading the referenced schema/resolver files to S3 and use the corresponding S3 locations (strings) as input parameters to the synthesized CFN template during deployment. Very similar to how lambda.CfnParametersCode, see this example.

Since pipelines.CdkPipeline now supports Assets, I think sth. like the following would best cover all use cases (cdk deploy and pipeline deployments using pipelines.CdkPipeline)

const api = new appsync.GraphQLApi(this, 'GraphQLApi', {
  name: `GraphQLApi`,
  schemaDefinition: appsync.SchemaDefinition.fromAsset('./schema.graphql'),
});

someDataSource.createQueryResolver({
  field: 'getHello',
  requestTemplate:  appsync.MappingTemplate.fromAsset('./resolvers/getHello-request-mapping-template.vtl'),
  responseTemplate: appsync.MappingTemplate.fromAsset('./resolvers/getHello-response-mapping-template.vtl'),
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/aws-appsync module - AWS Documentation
The @aws-cdk/aws-appsync package contains constructs for building flexible APIs that use GraphQL. import * as appsync from '@aws-cdk/aws-appsync';. (Example ...
Read more >
The fullstack guide to creating AppSync APIs with the AWS CDK
AWS AppSync is a managed GraphQL service that helps in building scalable GraphQL ... Using the L2 Cognito construct (APIs made for the...
Read more >
awslabs/aws-cdk - Gitter
I have an AppSync API and I want to deploy it through CodePipeline. So far I have: ... The same problem also arises...
Read more >
The AWS CDK, Or Why I Stopped Being a CDK Skeptic
L2 Constructs, on the other hand, are smarter and provide ... dynamoDbGetItem() to create an AppSync resolver mapping template to put an ...
Read more >
AWS CDK 101 - GraphQL using AppSync with dynamodb
Here specifically we have chosen graphql using AWS appsync to perform. ... using event source mapping L2 construct with simple override with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found