dougmoscrop / serverless-plugin-split-stacks

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

Big Cloudformation Problem #114

Open lunizxx opened 4 years ago

lunizxx commented 4 years ago

We were working for switching our large project to aws. We've noticed about serverless framework and started to build our project on serverless framework. We've switched all the code to the aws serverless with serverless framework. But finally when we deploy the whole project, it gave us the Cloudformation stack limit error. And all the issues are starting from there.

It gave us the traditional stack size limit error, resource number limit error, after output limit error etc.. We solved all that problems one-by-one using "serverless-plugin-split-stacks". Finally it gave us and another error: "Resource dependency error has occured while using nested stacks". Here is my plugin setup:

splitStacks:
    nestedStackCount: 60
    perFunction: false
    perType: false
    perGroupFunction: true
    stackConcurrency: 5
    resourceConcurrency: 10 

Firstly we read all the documents in the internet and blog posts in the serverless framework blog. We noticed a good blog post about that situation: https://serverless.com/blog/serverless-workaround-cloudformation-200-resource-limit/

For this 4 solutions ( 1 one of them was the plugin that i told above ) in that blog post, each of them has their own big problems. Let's start with the first one:

  1. "Break your web API into microservices": In that logic, we're generating multiple serverless.yaml files for each of our endpoints ( users, blogs, posts etc... ) Okay, we're also connecting them to the same domain by using custom domain property. But what happens if it comes to test our application in localhost? We have no domain there, do we have to run serverless-offline command for each of that endpoints one-by-one. Wait wait wait... what was the serverless framework's goal, making everything automatic (!) Even if we set up an npm script to run all these serverless applications as offline, we cannot run them at the same port. That is how big problems we'll have when we use that solution. I think it's enough for that one.

  2. "Handle routing in your application logic": That was the craziest solution i've ever heard. When i contact to AWS support, one of the guy told me that one as well. Think that a single lambda function runs for each endpoint. And then we're going to handle them in that function by using that function as router. Wait wait wait... how can we laser focus for each of that endpoints, we're not going to have multiple endpoints anymore, one lambda function, does everything. Doesn't make that sense, it makes everything more confused and impossible to maintanable. It's enough for that solution as well.

  3. "Split your stacks with plugins". As i told very first section above, we tried to use one of the most popular serverless plugin for that job and there are resource dependency errors are happened. At the end of the day again there is an error. Pff...

  4. "Pestering your AWS rep to get the CloudFormation limit increased": Sadly, even if we are AWS Premium support member, they CANNOT increase that limit. Even if they increase one of that limits, there will again occur another limit problem, even if they increased that another limit problem when application grows, there will be another limit exceedings. And what happens if we use another aws account, again you have the basic limits. But i'm saying again, there'll always be limits that will throw an error. So that solution is not a solution.

Finally what i want to tell and need help:

Thanks in advance.

dougmoscrop commented 4 years ago

I agree, CloudFormation is really sub-par here. But this is the story with most of AWS - they leave a lot of the details to the developer. I personally would not use AWS if I had the choice :)

You can use nested stacks as well as cross-stack imports. I suggest you look at my other plugin, serverless-plugin-bootstrap - or even just the idea -- you should have prerequisite stacks for things like databases, vpcs, anything that would suck to have to delete/recreate. Then just deploy your 'application tier' using Serverless.

Splitting with this plugin will work, you just have to do more effort -- you have to manually declare how you want things to be split; this plugin is more like a framework with a few very conservative defaults, it is not a magic bullet.