Skip to content

Appsync and split strategy #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
NevRA opened this issue Jan 18, 2022 · 2 comments
Open

Appsync and split strategy #176

NevRA opened this issue Jan 18, 2022 · 2 comments

Comments

@NevRA
Copy link

NevRA commented Jan 18, 2022

Hey. Thanks for the lib! I have a question about Appsync.

By default, all Appsync resources will be stored in the root stack, so If I have hundreds of resolvers it will not work for me.
If I use recommended approach from the serverless-appsync-plugin:

stacks-map.js:

module.exports = {
  'AWS::AppSync::ApiKey': { destination: 'AppSync', allowSuffix: true },
  'AWS::AppSync::DataSource': { destination: 'AppSync', allowSuffix: true },
  'AWS::AppSync::FunctionConfiguration': { destination: 'AppSync', allowSuffix: true },
  'AWS::AppSync::GraphQLApi': { destination: 'AppSync', allowSuffix: true },
  'AWS::AppSync::GraphQLSchema': { destination: 'AppSync', allowSuffix: true },
  'AWS::AppSync::Resolver': { destination: 'AppSync', allowSuffix: true }
}

It will not change anything, because all the same, resolvers and other things will be together

So the idea is to split this somehow into smaller chunks. I found this solution to work for me.

const ServerlessPluginSplitStacks = require('serverless-plugin-split-stacks')

const NUMBER_OF_BINS = 10
let COUNT = 0

ServerlessPluginSplitStacks.resolveMigration = function (resource, logicalId, serverless) {
  COUNT += 1 
  const bin = COUNT % NUMBER_OF_BINS

  if (resource.Type == 'AWS::AppSync::Resolver'){
    return { destination: `GraphQLResolverStack${Math.abs(bin)}`, allowSuffix: true }
  }
  
  if (resource.Type == 'AWS::AppSync::FunctionConfiguration'){
    return { destination: `FunctionConfigurationStack${Math.abs(bin)}`, allowSuffix: true }
  }

  if (resource.Type == 'AWS::AppSync::DataSource'){
    return { destination: `GraphQLDataSourceStack${Math.abs(bin)}`, allowSuffix: true }
  }

  if (resource.Type == 'AWS::AppSync::GraphQLApi'){
    return { destination: `GraphQLApiStack${Math.abs(bin)}`, allowSuffix: true }
  }

  if (resource.Type == 'AWS::AppSync::GraphQLSchema'){
    return { destination: `GraphQLSchemaStack${Math.abs(bin)}`, allowSuffix: true }
  }

  // Fallback to default:
  return this.stacksMap[resource.Type]
}

But I'm wondering what the pitfalls are, will there be any problems with it in the future? And what strategy to use is safer?

For example with config:

nestedStackCount: 20
perFunction: false
perType: false
perGroupFunction: true

it will create some additional stacks to hold these new AppSync resources, and it is not clear whether this is a problem or not

Thanks!

@dmr121
Copy link

dmr121 commented Apr 1, 2022

@NevRA Where did you place that custom bit of code with the ServerlessPluginSplitStacks.resolveMigration? I am having the same problem but I don't know which file to put that piece of code into.

@katesclau
Copy link

@dmr121 Same stacks-map.js 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants