Getting @aws_subscribe to work with CDK aws-appsync


For the application I'm building Amplify is an overkill. I've been able to manage to build graphQL with appsync and cdk only at this point. Now, I'm running into issue with @aws_subscribe -- it just does not work for me. I'm wondering if the directives like this require Amplify to be aded and initialized? Is there any way to initialize and process graphQL subscriptions with CDK api directly?

My schema.graphql contains certain definitions:

type Message{  
  chatUuid: String!
  uuid: String!
  messageUuid: String!
  text: String! 
  createdAt: AWSDateTime!  
  updatedAt: AWSDateTime!  

    chatUuid: String!
    uuid: String!
    messageUuid: String!
    text: String! 
  ): Message

type Subscription {
  onSendMessage(chatUuid: String!): Message    
    @aws_subscribe(mutations: ["sendMessage"])

And here is how I'm initializing my graphQL with CDK off of that definition file:

const api = new appsync.GraphqlApi(this, `${deployEnv()}-WiSaw-appsyncApi-cdk`,
        name: `${deployEnv()}-cdk-wisaw-appsync-api`,
        schema: appsync.Schema.fromAsset('graphql/schema.graphql'),
        authorizationConfig: {
          defaultAuthorization: {
            authorizationType: appsync.AuthorizationType.API_KEY,
            apiKeyConfig: {
              expires: cdk.Expiration.after(cdk.Duration.days(365)),

For debugging purposes, tried to attach a resolver to the subscription:

export default async function main(
) {


  return {}

In the log see the following:

  event: {
    arguments: {},
    identity: null,
    source: null,
    request: { headers: [Object], domainName: null },
    prev: null,
    info: {
      selectionSetList: [Array],
      selectionSetGraphQL: '{\n  chatUuid\n  createdAt\n  messageUuid\n  text\n  updatedAt\n  uuid\n}',
      fieldName: 'onSendMessage',
      parentTypeName: 'Subscription',
      variables: {}
    stash: {}

At this point, I'm running out of things to try. Any help or direction would be highly appreciated.

  • I know this is definately possible. Am trying to recreate your example but it contains some typos.

asked 2 years ago352 views
1 Answer

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions