Skip to content

Hitting CloudFormation templateBody limit when deploying #1740

Closed

Description

@kid
Serverless Framework Version:

1.0.0-alpha-2

Operating System:

Mac OS X 10.11.5

Discussion:

Once you have a certain number of handlers and events, the deployment will fail because the CloudFormation template will hit the limit allowed when using the templateBody parameter of ValidateStack / CreateStack / UpdateStack
That limit is 51200 characters (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html)

To avoid hitting this limit, Serverless should upload the CloudFormation stack to S3 first so that can use the templateUrl parameter instead of templateBody.
This means the deployment bucket should be created separately.

Our serverless.yaml file is currently about 240 lines with less than 20 handlers and that is already too much

Activity

  1. robizz commented on Aug 3, 2016

    @robizz

    +1 please :)

  2. gpiccinni commented on Aug 3, 2016

    @gpiccinni

    +1

    To help with limits it should work as follows:

    • Upload files (even more than 1) on s3
    • Use the s3 url in the s-resources-cf.json as nested stacks

    This should help with all limits (bytes, resources, outputs)

    Thanks

  3. flomotlik commented on Aug 3, 2016

    @flomotlik
    Contributor

    @kid thanks for reporting, this is definitely a big problem and needs to be resolved. Putting this into the next milestone.

  4. added this to the v1.0.0-beta.2 milestone on Aug 3, 2016
  5. flomotlik commented on Aug 4, 2016

    @flomotlik
    Contributor

    The current solution I can think of is creating the stack with template body (it only has the S3 bucket in there). Then as soon as we do updates to the stack to actually create functions and the whole infrastructure we push the template file into S3 and point to it for deployment. That should resolve the issue and work well with our current infrastructure. @pmuens @eahefnawy any other ideas?

    This should also not be too complicated to implement imho.

  6. pmuens commented on Aug 4, 2016

    @pmuens
    Contributor

    Just putting it inside the S3 bucket sounds like the best solution 👍 .

    Shouldn't be that hard to implement either.

  7. codepreneur commented on Aug 4, 2016

    @codepreneur

    I switched to using only one endpoint/function per service (and putting them in separate folders with their own dependencies) long time ago...

  8. nicka commented on Aug 4, 2016

    @nicka
    Contributor

    @codepreneur How far are you taking this?

    I could see one service per model. For example a Lambda with multiple handlers (GET, POST etc.) and ApiGateway routes as substacks. Then a main stack with CloudFront origins to each models API GW endpoint. Without this you could easily hit 200 CF resources. Now if only serverless could output the s3 urls to the newly uploaded CF templates :)

  9. codepreneur commented on Aug 4, 2016

    @codepreneur

    @nicka when I build things, I exclusively choose either falcor or graphql which means I only ever have one (declarative) endpoint (none of the GET, POST, PUT mess with imperative API). REST is a sinking ship you need to get out of :)

  10. nicka commented on Aug 4, 2016

    @nicka
    Contributor

    A bit off topic
    @codepreneur Haha yes I know about REST vs. graphql(never touched falcor). But still how do you handle multiple Lambda's and one graphql endpoint?

  11. pmuens commented on Aug 4, 2016

    @pmuens
    Contributor

    @nicka you might want to take a look at this project: https://github.com/serverless/serverless-graphql

    It runs Serverless v0 but handles everything through one graphql endpoint.

  12. eahefnawy commented on Aug 4, 2016

    @eahefnawy
    Contributor

    @flomotlik yep that looks right. Two things to note though with this setup is that the first stack creation (the one happening without S3) will not only include S3 bucket, but it'll also include any custom resources and IAM policy statements (including the ones added by the user). Because merging those custom resources happen at the intializeResources step, which happen before createStack. The rest of resources however (functions/events...etc which make up most of the stack template) will be handled via S3.

    I'll doubt that users would have tons of custom resources to hit the limit on stack creation. So this should work fine.

  13. eahefnawy commented on Aug 4, 2016

    @eahefnawy
    Contributor

    @kid @codepreneur just a quick note about architecture. A Service is not meant to be your entire project, but rather a micro part of it that handles a specific functionality. If we follow microservices principles, your project would have a bunch of services, each of which would contain minimal amount of functions that are specific to the service intended purpose.

    Of course if you choose to go with a single service, we'd definitely support that, but I'd say it's an anti pattern :)

  14. nicka commented on Aug 4, 2016

    @nicka
    Contributor

    @pmuens Wow, the project improved a lot. But isn't this creating one big Lambda function? That's a thing I try to avoid at all times. Will review later, thanks 👍

  15. pmuens commented on Aug 4, 2016

    @pmuens
    Contributor

    @nicka yes, you're right.

    It's one large lambda function (which then includes the other parts of the service).

  16. flomotlik commented on Aug 4, 2016

    @flomotlik
    Contributor

    @eahefnawy there is an issue open and we're waiting for a PR at the moment that will remove custom resources from the initial stack creation. Deploying with the initial stack will lead to issues as a user might have defined something that fails, or a custom resources wants to use a resource we create for them

  17. jeffski commented on Aug 5, 2016

    @jeffski

    Been playing about with serverless v1 today and it would be good to have some guidance/docs/best practice on how to structure your projects/services/microservices. I know there will be lots of opinions but some starting points would be good. I'm a little bit lost on this having got familiar with some of the v0.5 examples.

  18. self-assigned this
    on Aug 12, 2016
  19. pmuens commented on Aug 14, 2016

    @pmuens
    Contributor

    While looking into it I found in the SDK that the there will also be a limit when one specifies a TemplateURL which points to a CloudFormation file in S3 (460, 800 bytes).

    Has anyone some experiences with this limitation? Seems to be suboptimal if even the upload to S3 won't remove the CloudFormation file size limit.

    https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudFormation.html#createStack-property

  20. flomotlik commented on Aug 15, 2016

    @flomotlik
    Contributor

    Here are the details on Cloudformation limits: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html

    Imho the S3 limit is 9X from what we have right now. So judging by the issue description that would be at least 160-180 handlers and additional config. At that point my assumption would be that it should be split up into separate services as you have hundreds of functions defined in one file.

    So going with S3 deployment at first and making sure everything we create at the moment has a small CF footprint should yield good results for us. I doubt a lot of people will run into this 9x limit. And if there should be easy ways to change the way this is done.

  21. modified the milestones: v1.0.0-beta.2, , on Aug 15, 2016
  22. pmuens commented on Aug 17, 2016

    @pmuens
    Contributor

    Will be resolved with #1886

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions