-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested stack issue #90
Comments
You should use |
@sanathkr how would you do that with a nested stack? There's no ChangeSet resource. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html |
+1 |
1 similar comment
+1 |
Came here to mention something specifically about the Change Set requirement and Nested stacks. Currently Change Sets do not traverse Nested stacks, so I'm going to operate under the assumption that you can not nest with SAM which is a major pitfall. |
Only the reverse seems to work, i.e. you can have a SAM enabled template as the parent template just not the child, which is quite a bummer and limiting. |
This really should be tagged as a bug not a question @sanathkr |
How about including If not, this is a bug that needs to be fixed. |
@sanathkr tried that before and just did it again to be sure, same error |
Same here EDIT: well, there are other resources that we can nest as @alanwill mentioned, which alleviates the problem in the short term but that's not the point. Organizing stacks by functionality would be good practice, but right now we're forced to put all of the functions into the same SAM template, and split off their supporting resources into nested stacks, even though logically we'd group functions by their resource domain, so to speak. EDIT2: as mentioned by @dejonghe, this comes down to a bigger question of adding CloudFormation support to create change sets for nested stacks (which would be good by itself). Without that, I don't see how the current SAM implementation could solve this issue (i.e transforms require change sets). EDIT3: the 200 limit above was actually reached after template "expansion" by transform. I have just 100 resources in total, including 54 SAM functions. Each function currently gets expanded into a "regular" CloudFormation function plus a function role resource, and if we bind them to an API (which is a crucial piece of the whole model), each trigger also gets 2 So this places an upper limit on the total number of functions in SAM of ~ 70, if there are no other resources. A reasonable API can have more than that (and there are plenty of functions that can comprise the backend without directly serving the API). One workaround for us besides making space for ~15 more functions (which we will hit pretty soon), is to use regular functions, which sort of defeats the purpose of SAM. Another alternative is creating multiple independent SAM stacks, and deploying them through changesets in a script, but that may be more cumbersome than simply using nested stacks. Could we at least request that the 200 resource limit is increased globally by the CloudFormation team? I'm not sure what the proper channel for that is, as the official Support request doesn't allow to specify this limit (only the one for the total number of stacks). This would at least allow most teams to continue their work without interruption, until this is resolved (which may take a while, if I understood correctly). (Sorry if that's beyond the scope of this issue) |
Any thoughts on this @sanathkr I now have a workaround to a workaround just to try to get around this. The workaround was to put all the SAM resources in the parent stack, but then that go too large in a single stack so I have another workaround to that. Any guidance you can provide here would be super helpful. |
What I've done is create a CFN Template launcher in python with Boto that goes through all the steps. I have a Yaml file that defines stacks and can grab output from one stack and pass it as a parameter to another. |
@sanathkr Any news regarding this issue? It'd be so great to have that fixed. |
Having the same issue, any update @sanathkr? |
We moved away from SAM due to this problem. At the cost of more verbose templates and an extra packaging step, we also got more flexibility with 'native' resources. |
Even further than that, this issue was a factor in my team dropping CloudFormation in favour of Terraform. At least with Terraform, we can fork and fix issues ourselves, rather than just waiting. |
@dinvlad could you share what your template looks like? |
@aehlke serverless functions can be replaced with 3 resources: Function:
Type: AWS::Lambda::Function
Properties:
Handler: index.get
Environment:
Variables:
VAR_NAME: !Ref ...
Runtime: nodejs6.10
Code:
S3Bucket: !Ref LambdaBucket
S3Key: !Ref LambdaPackageKey
Role: !GetAtt FunctionRole.Arn
FunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: FunctionRole
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- service:Action
Resource:
- !GetAtt Resource.Arn
FunctionRolePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref Function
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn:
!Sub arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiId}/${ApiStage}/GET/... Before execution of the stack, you also need to upload lambda package as a zip file to |
That's not what we have in mind. More like it will perform the transform on each individual template |
Hope there will be a possibility in AWS SAM CLI to transform SAM template locally soon. Then I will be able to have the transformed stack as a nested stack in my master stack. @brettstack When this feature will be available to use? |
I can't comment on timeline, but we're actively talking about this internally and we'll create a thread in the SAM CLI repo for more discussion and details soon. You could potentially hack this together yourself with |
@brettstack: Just out of curiosity: What's the motivation to solve that by applying the transformations locally? Couldn't that be done in the same way by CloudFormation as the transformation of the parent template? |
We want to do local transform for other reasons anyway. Two birds sort of deal. |
I happened to run into the same nested SAM template issue a couple of days ago. Although it would be great if SAM templates would be expanded automatically by CloudFormation, for now I use sam-translate.py as workaround locally and for deployment.
StepsI didn't have
As far as I can tell
Example of the root stackNote: The translated template is a JSON file, not YAML. AWSTemplateFormatVersion: 2010-09-09
Description: Nested stack featuring SAM
Parameters:
TemplateBucket:
Type: String
Default: deployment-artifacts
Description: |
The bucket for the CloudFormation templates and packaged SAM application.
Resources:
MyAppStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub https://s3.amazonaws.com/${TemplateBucket}/templates/my-app.cfn.json |
FWIW, I think local transformations are a grand idea. I have a CodePipeline pipeline set up, the CloudFormation |
Thanks @christianklotz for sharing the local transformation workaround, however I still seem to be running into the same problem even with nested SAM. Basically my SAM is now getting too big just getting over 200 resources. CloudWatch Log and DynamoDB are already separated out so what is in SAM are the Roles, API, Lambda, API Keys, Usage Plan. I followed your instructions with the below approaches
I must have missed something from your instructions, really appreciate for your help here. |
This is a top priority for us. Sorry for the headaches 🤕 |
I understand that there is still no direct solution to use CreateStack with transforms. But is there a workaround where I can use REPLACE_ON_FAILURE action mode with a sam template? I would need this to reduce our testing time which for now is quite some time as any failure makes us undeploy the stack and redeploy again. |
@sanathkr, I am also getting the same issues I will execute this file. I am getting an error like this "CreateStack cannot be used with templates containing Transforms." |
@Amanfavas your template.template files contains serverless functions. There are 2 ways you can fix it.
Or
|
@revolutionisme Thanks for replying my comment. I am used CREATE_CHANGESET for creating new API and lambda.But it getting more than 200 resources file is not possible. Like that. And also I changed AWS::Serverless::function to AWS::lambda::function. But that one also not working.If anybody know solution kindly provide the solution |
Maybe someone else can help you then, also posting the exact error you got after applying the changes helps as well. |
@revolutionisme my exact issue already I posted in above. |
@Amanfavas Cloudformation doesn't support transforms (like the SAM transform) in nested stacks. The template that you provide to the Edit: I mistakenly wrote |
I followed the example posted by @dinvlad on Sep 16, 2017 to get around the limit. You should give it a go. |
@keetonian In the template I provide AWS::Serverless::Stack as the resource type. But it getting an error like this |
@Amanfavas |
@keetonian Sorry,I didn't get the nest vanilla cloudformation templates |
Nested transforms have been released! Check out SAM v1.9.0 release notes for more information! |
* Add support for Event Filtering (DDB, Kinesis, SQS) * PR feedback Rename test file. Move to a variable the list of event types that have event filtering.
* Add support for Event Filtering (DDB, Kinesis, SQS) * PR feedback Rename test file. Move to a variable the list of event types that have event filtering.
* feat: add support for event filtering (DDB, Kinesis, SQS) (#90) * Add support for Event Filtering (DDB, Kinesis, SQS) * PR feedback Rename test file. Move to a variable the list of event types that have event filtering. * chore: change a test case that CFN doesn't support (#98) Co-authored-by: Renato Valenzuela <37676028+valerena@users.noreply.github.com>
I am trying to make stack with nested stacks, but when i have Transform in nested stack, i get an error:
CreateStack cannot be used with templates containing Transforms
. If this error is expected, this should be added somewhere to docs, that only parent stack should haveTransforms
.In case i delete
Transforms
from nested stacks, i getCircular dependency between resources: [ApiGatewayApi, InviteUserFunction, LambdaInvokePermission]
, which i do not have if i create this stack separately.Here is part of nested stack template
The text was updated successfully, but these errors were encountered: