dougmoscrop / serverless-plugin-split-stacks

A plugin to generate nested stacks to get around CloudFormation resource/parameter/output limits
300 stars 72 forks source link

Circular dependency between resources - How to solve it ? #105

Open JeremieDemarchez opened 4 years ago

JeremieDemarchez commented 4 years ago

Hello,

I have the following error :

Circular dependency between resources: [UpdatePhoneNumberLambdaFunctionDeploymentGroup, UpdatePhoneNumberFunctionErrorsAlarm, UpdatePhoneNumberLambdaPermissionApiGateway, UpdatePhoneNumberLambdaFunctionAliasLive, UpdatePhoneNumberFunctionDurationAlarm, ApiGatewayMethodUpdatephonenumberPost]

This is due to the use of the plugin serverless-plugin-canary-deployments, really usefull for continuous deployment.

I tried specify almost any kind of resources in the stacks-map.js, but it does not work :

module.exports = {
    'AWS::ApiGateway::Resource': false,
    'AWS::ApiGateway::RestApi': false,
    'AWS::ApiGateway::Deployment': false,
    'AWS::ApiGateway::*': false,

    'AWS::Logs::SubscriptionFilter': false,

    'AWS::Lambda::Permission': false,
    'AWS::Lambda::Alias': false,
    'AWS::Lambda::Version': false,
    'AWS::Lambda::EventSourceMapping': false,
    'AWS::Lambda::EventInvokeConfig': false,
    'AWS::Lambda::Function': false,
    'AWS::Lambda::LayerVersion': false,
    'AWS::Lambda::LayerVersionPermission': false,

    'AWS::CodeDeploy::Application': false,
    'AWS::CodeDeploy::DeploymentConfig': false,
    'AWS::CodeDeploy::DeploymentGroup': false,

    'AWS::CloudWatch::Alarms': false,
    'AWS::CloudWatch::AnomalyDetector': false,
    'AWS::CloudWatch::Dashboard': false,
    'AWS::CloudWatch::InsightRule': false
};

I don't understand how we can determine what we must add in the stacks-map.js to solve the circular dependancies problem.

1) How can I determine the ressouces to add to the file stacks-map.js ?

2) Do you know what I must ad to this file to make the project compatible with the plugin serverless-plugin-canary-deployments ?

Thank you for any help. Regards

tomoconnor-woebot commented 4 years ago

@JeremieDemarchez

I had a problem with circular dependencies too, in my case it was due to having a custom authorizer function on some of my API Gateway endpoints. I resolved the problem by keeping authorizer related resources in the main stack:

module.exports = (resource, logicalId) => {
  // Keep resources associated with the authorize function in the main stack
  if (logicalId.startsWith('Authorize')) {
    return false;
  }
};

Your issue might be different, but looking at the compiled templated for the deployment helped me to find the source of the problem. I found it in the deployment S3 bucket. There's a link to it in the CloudFormation resources for the main stack.