Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Created October 10, 2022 06:25
Show Gist options
  • Save dhavaln/ea274ea5b314127c8a3d64f4b331ab80 to your computer and use it in GitHub Desktop.
Save dhavaln/ea274ea5b314127c8a3d64f4b331ab80 to your computer and use it in GitHub Desktop.
Serverless framework AppSync service with custom split stacks
custom:
splitStacks:
nestedStackCount: 50
perFunction: false
perType: false
perGroupFunction: false
module.exports = (resource, logicalId) => {
console.log(resource.Type, logicalId);
// Keep the deployment bucket with default setup
if( logicalId.startsWith('ServerlessDeploymentBucket') || resource.Type == 'AWS::Lambda::Permission'){
return
}
if( (resource.Type == 'AWS::S3::Bucket' || resource.Type == 'AWS::S3::BucketPolicy') ){
return { destination: 'S3GroupStack', allowSuffix: true, force: true };
}
if ( resource.Type == "AWS::Logs::LogGroup" && !logicalId.endsWith('GraphQlApiLogGroup') ) {
return { destination: 'LogGroupsStack', allowSuffix: true, force: true };
}
// Appsync specific resources
if( resource.Type == 'AWS::AppSync::GraphQLSchema' ||
resource.Type == 'AWS::AppSync::FunctionConfiguration' ||
resource.Type == 'AWS::AppSync::DataSource' ||
resource.Type == 'AWS::AppSync::Resolver' ){
return { destination: 'AppSync', allowSuffix: true, force: true };
}
// Falls back to default
};
@dhavaln
Copy link
Author

dhavaln commented Oct 10, 2022

Likely errors:

  • Circular dependencies - This you can easily understand and resolve by going through your resources and keeping the related resources in the same stack.
  • Resource already exists in another stack - This will come if you are trying to deploy the changes on the existing stage that is not using split stack or has a different stack structure. For me, the closest solution was to deploy a new stage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment