Skip to content

Make AppSync and MappingTemplate L2-constructs work with CodePipeline deployments #8052

@asterikx

Description

@asterikx

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:

let definition;
if (props.schemaDefinition) {
definition = props.schemaDefinition;
} else if (props.schemaDefinitionFile) {
definition = readFileSync(props.schemaDefinitionFile).toString('UTF-8');
} else {
throw new Error('Missing Schema definition. Provide schemaDefinition or schemaDefinitionFile');
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-appsyncRelated to AWS AppSync@aws-cdk/aws-codepipelineRelated to AWS CodePipelineclosed-for-stalenessThis issue was automatically closed because it hadn't received any attention in a while.effort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions