You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hitting CloudFormation templateBody limit when deploying #1740
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
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.
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 :)
@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 :)
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?
@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.
@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 :)
@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 👍
@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
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.
Reacted by Eslam λ Hefnawy, Philipp Muens and Ryan Walters
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.
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.
Activity
robizz commentedon Aug 3, 2016
+1 please :)
gpiccinni commentedon Aug 3, 2016
+1
To help with limits it should work as follows:
This should help with all limits (bytes, resources, outputs)
Thanks
flomotlik commentedon Aug 3, 2016
@kid thanks for reporting, this is definitely a big problem and needs to be resolved. Putting this into the next milestone.
flomotlik commentedon Aug 4, 2016
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.
pmuens commentedon Aug 4, 2016
Just putting it inside the S3 bucket sounds like the best solution 👍 .
Shouldn't be that hard to implement either.
codepreneur commentedon Aug 4, 2016
I switched to using only one endpoint/function per service (and putting them in separate folders with their own dependencies) long time ago...
nicka commentedon Aug 4, 2016
@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
serverlesscould output the s3 urls to the newly uploaded CF templates :)codepreneur commentedon Aug 4, 2016
@nicka when I build things, I exclusively choose either
falcororgraphqlwhich 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 :)nicka commentedon Aug 4, 2016
A bit off topic
@codepreneur Haha yes I know about
RESTvs.graphql(never touchedfalcor). But still how do you handle multiple Lambda's and onegraphqlendpoint?pmuens commentedon Aug 4, 2016
@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
graphqlendpoint.eahefnawy commentedon Aug 4, 2016
@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
intializeResourcesstep, which happen beforecreateStack. 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.
eahefnawy commentedon Aug 4, 2016
@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 :)
nicka commentedon Aug 4, 2016
@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 👍
pmuens commentedon Aug 4, 2016
@nicka yes, you're right.
It's one large lambda function (which then includes the other parts of the service).
flomotlik commentedon Aug 4, 2016
@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
jeffski commentedon Aug 5, 2016
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.
pmuens commentedon Aug 14, 2016
While looking into it I found in the SDK that the there will also be a limit when one specifies a
TemplateURLwhich 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
flomotlik commentedon Aug 15, 2016
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.
pmuens commentedon Aug 17, 2016
Will be resolved with #1886