AWS CloudFormation limit of 200 maximum allowed resources
Problem
This is a Bug Report Description - What went wrong? After upgrading my project from 0.5.6 to 1.0.0 I attempted to deploy and received this error: `Template format error: Number of resources, 202, is greater than maximum allowed, 200` - What did you expect should have happened? I expect that this should have worked since there is no limitation on AWS that should forbid this, and it was working on 0.5.6. Serverless should break up the template resources automatically to make this possible. With the current method you are forced to break up the service, which should not be necessary. This causes problems with general project structure, custom domain mapping, and shared dependencies. - What was the config you used? The example config below will generate the error by creating 65 endpoints. [code block] - What stacktrace or error message from your provider did you see? `Template format error: Number of resources, 214, is greater than maximum allowed, 200` another possible error `Template may not exceed 460800 bytes in size.` Additional Data - _Serverless Framework Version you're using_: 1.0.2 - _Operating System_: Windows 10 x64 - _Stack Trace_: N/A - _Provider Error messages_: See above
Error Output
error: `Template format error: Number of resources, 202, is greater than maximum allowed, 200`
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Refactor CloudFormation Template to Reduce Resource Count
AWS CloudFormation limits the number of resources in a single stack to 200. The upgrade to version 1.0.0 of the Serverless Framework may have introduced additional resources or endpoints that exceed this limit, leading to the deployment failure.
Awaiting Verification
Be the first to verify this fix
- 1
Identify Resource Count
Review the generated CloudFormation template to identify the total number of resources being created. This can be done by running the command `serverless package` and inspecting the `cloudformation-template-update.json` file.
bashserverless package - 2
Split Resources into Multiple Stacks
Refactor your Serverless service to split the resources into multiple stacks. You can achieve this by creating separate services for different functionalities or domains and using AWS CloudFormation StackSets or nested stacks to manage dependencies.
yamlservice: my-service functions: firstFunction: handler: handler.first resources: Resources: MyFirstResource: Type: 'AWS::Lambda::Function' - 3
Use Serverless Framework's `--stage` Option
Deploy different stages of your application separately using the `--stage` option. This allows you to group related resources and reduce the overall count in each deployment.
bashserverless deploy --stage dev - 4
Optimize Resource Usage
Review your configuration for any redundant resources or endpoints. Consider consolidating functions or using AWS API Gateway features like `ANY` methods to reduce the number of endpoints.
yamlfunctions: api: handler: handler.api events: - http: path: /api method: ANY - 5
Test Deployment
After making the changes, redeploy your application using the Serverless Framework. Monitor the deployment process for any errors related to resource limits.
bashserverless deploy
Validation
Confirm that the deployment completes successfully without exceeding the resource limits. Check the AWS CloudFormation console to ensure the stack is created without errors and verify the number of resources in the stack.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep