Skip to content
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

Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block #9

Open
gotha opened this issue Sep 22, 2017 · 50 comments
Open
Assignees

Comments

@gotha
Copy link

gotha commented Sep 22, 2017

Hey, I installed the plugin and when I try to deploy I get this:

Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Invoke aws:package:finalize
Serverless: [serverless-plugin-split-stacks]: Summary: 87 resources migrated in to 3 nested stacks
Serverless: [serverless-plugin-split-stacks]:    Resources per stack:
Serverless: [serverless-plugin-split-stacks]:    - (root): 125
Serverless: [serverless-plugin-split-stacks]:    - APINestedStack: 24
Serverless: [serverless-plugin-split-stacks]:    - PermissionsNestedStack: 31
Serverless: [serverless-plugin-split-stacks]:    - VersionsNestedStack: 32
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Invoke aws:common:validate
Serverless: Merged stage variables into ApiGateway Deployment
Serverless: Invoke aws:deploy:deploy
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (13.75 MB)...
Serverless: Validating template...

  Error --------------------------------------------------

  The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template

I am using serverless 1.21.1

Any ideas how can I fix this ?

@dougmoscrop
Copy link
Owner

dougmoscrop commented Sep 22, 2017 via email

@gotha
Copy link
Author

gotha commented Sep 25, 2017

@dougmoscrop I tried with 3991fb6 and cd6578a getting the same results.

With: 4b14c6d I see different error:

 An error occurred: CoreNestedStack - Embedded stack arn:aws:cloudformation:eu-central-1:xxxx:stack/project-CoreNestedStack-xxx/xxx was not successfully created: The following resource(s) failed to create: [IamRoleLambdaExecution].

I haven't specified IAM Role in the serverless file so I am not really sure where this is coming from.

@dbligh
Copy link

dbligh commented Sep 28, 2017

Hi,

pulled the latest version and I also seem to get the same error (upgraded serverless to latest)

WARNING in ./node_modules/colors/lib/colors.js
127:29-43 Critical dependency: the request of a dependency is an expression
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Invoke aws:package:finalize
Serverless: [serverless-plugin-split-stacks]: Summary: 85 resources migrated in to 3 nested stacks
Serverless: [serverless-plugin-split-stacks]:    Resources per stack:
Serverless: [serverless-plugin-split-stacks]:    - (root): 95
Serverless: [serverless-plugin-split-stacks]:    - APINestedStack: 30
Serverless: [serverless-plugin-split-stacks]:    - PermissionsNestedStack: 27
Serverless: [serverless-plugin-split-stacks]:    - VersionsNestedStack: 28
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:deploy:deploy
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (4.23 MB)...
Serverless: Validating template...

  Error --------------------------------------------------

  The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

Error: The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template
    at provider.request.catch (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\lib\validateTemplate.js:25:13)
From previous event:
    at AwsDeploy.validateTemplate (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\lib\validateTemplate.js:20:12)
From previous event:
    at AwsDeploy.BbPromise.bind.then (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\index.js:117:39)
From previous event:
    at Object.aws:deploy:deploy:validateTemplate [as hook] (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\index.js:113:10)
    at BbPromise.reduce (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:360:55)
From previous event:
    at PluginManager.invoke (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:360:22)
    at PluginManager.spawn (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:378:17)
    at AwsDeploy.BbPromise.bind.then (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\index.js:91:48)
From previous event:
    at Object.deploy:deploy [as hook] (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\index.js:87:10)
    at BbPromise.reduce (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:360:55)
From previous event:
    at PluginManager.invoke (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:360:22)
    at PluginManager.run (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:391:17)
    at variables.populateService.then (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:99:33)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
    at Serverless.run (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\lib\Serverless.js:86:74)
    at serverless.init.then (C:\Users\Main\AppData\Roaming\npm\node_modules\serverless\bin\serverless:39:50)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     win32
     Node Version:           6.10.3
     Serverless Version:     1.23.0

@dougmoscrop dougmoscrop self-assigned this Oct 4, 2017
@eliasisrael
Copy link

I'm getting this same error message. Was there any fix or workaround?

@eliasisrael
Copy link

Followup: Any chance it's an interaction with the serverless-aws-documentation plugin?

@cdichiara
Copy link

Stuck on this bug ... any info on this? I'm using v1.3.1 of this plugin ... and I'm using the serverless-aws-documentation plugin, I'll try to hunt this down from the outside.

@dougmoscrop
Copy link
Owner

any chance you could share your CF json?

also does this happen when you deploy a fresh stage? there are certain configs of CF that simply can't be 'upgraded' from not using this plugin to using this plugin (you have to tear down / set up a new deployment)

@cdichiara
Copy link

Yes, for sure ...

Post-Nested Stacks.zip
Prior to Nested Stacks.zip

Couple of caveats:

  1. This is a fresh stage. I am completely in agreement with you ... in fact the project we're working on is migrating a pre-existing stage into multiple stages, and so we've become well-versed on the limits of changing pre-existing stages. I think that's not the issue here.
  2. This isn't a vanilla test at this moment ... because I added some breakdowns above and beyond your default breakdowns. Primarily I'm using your plugin because DynamoDb autoscaling is such a resource hog. I can revert to a vanilla test for you later today, just to rule out any of my changes from the issue ... but based on the deterministic quality of this issue, I suspect it's less dependent upon my changes.

I'm looking to, but up to now I don't see a problem - everything seems correct re: references to the output ApiGatewayRestApi, outputting it from one stack, uses in the others ... I'm sure you'll be able to see the issue faster than me.

@cdichiara
Copy link

Here's the vanilla post-test:
Vanilla Post-Nested Stacks.zip

Same error message as before ... but now you can rule out any changes I made to stacks-map.js. Serverless plugins I'm using are:

  • serverless-aws-documentation
  • serverless-webpack
  • serverless-dynamodb-autoscaling
  • serverless-plugin-split-stacks

I'm going to keep on debugging over here, let you know if I see anything.

@eliasisrael
Copy link

It's definitely something to do with the serverless-aws-documentation plugin. When I remove that from my plugins, then split-stacks works without errors.

@cdichiara
Copy link

I think this in stacks-map.js:

// These two deletions are to solve a conflict caused with serverless-aws-documentation:
// https://github.com/9cookies/serverless-aws-documentation/issues/62
// https://github.com/dougmoscrop/serverless-plugin-split-stacks/issues/9
delete stacksMap['AWS::ApiGateway::Resource'];
delete stacksMap['AWS::ApiGateway::RestApi'];

May help.
deliveryhero/serverless-aws-documentation#62

I'm hitting another problem with the autoscaler, so I can't confirm it's all smooth sailing ... I'm also thinking there is a more refined solution, but I can handle the API resources being in the main resource file for now.

@sujameslin
Copy link

Is there any update with this issue?

@dougmoscrop
Copy link
Owner

Sorry for not being more responsive.

The documentation plugin is injecting resources during the deploy phase. I don't see why it needs to, or why you would want that. I would expect it to hook in to package.

So yes there is at least one problem here, which is that the documentation plugin should move their resource injection to the package phase.

@dougmoscrop
Copy link
Owner

@cdichiara - when you say problems with auto scale, do you mean to say that it's related to split-stacks? Or just that it's not working the way you want?

@sujameslin
Copy link

@dougmoscrop Can you give me some guidance how to move documentation plugin's resource injection to package phase?
So i can raise a PR to their repo?

Thanks in advance.

@dougmoscrop
Copy link
Owner

I would try:

https://github.com/9cookies/serverless-aws-documentation/blob/master/src/index.js#L22

Just make the first one before:package:package

@sujameslin
Copy link

@dougmoscrop Hey I don't think there's a before:package:package event in serverless lifecycle.
https://gist.github.com/HyperBrain/50d38027a8f57778d5b0f135d80ea406

@dougmoscrop
Copy link
Owner

Yeah, sorry - I mean something in that area. I haven't kept up on what they changed the names to!

try before:package:finalize but I think anything that is before this plugin is fine.

@sujameslin
Copy link

@dougmoscrop Thank you for the help.
It works like charm!

@cdichiara
Copy link

@dougmoscrop Thanks for responding ... honestly I've forgotten what I was thinking back then. If I recall, I think serverless-dynamodb-autoscaling was producing quite a lot of resources per scaled database (extra IAM roles, along with the necessary alarms, etc) ... but I thought there was some other issue that made it fail when I attempted to move the resources to a substack with your stack splitter. Anyways, I "solved" it by commenting out parts of the deployment, deploying, uncommenting out parts, deploying, etc. until the full deployment was up, and now since everything is a delta on the big deployment, we're "OK". Thanks for asking. 😄

@dougmoscrop
Copy link
Owner

Okay, great - I am going to close this, but @gotha and/or @dbligh if you still experience please open. You did not explicitly say that you were using the documentation plugin, so it could be some other plugin you are using that is inserting a resource after the package phase.

@cshivangi
Copy link

cshivangi commented Feb 8, 2018

Hi @dougmoscrop I'm running into the same issue and not using the documentation plugin
these are the plugins used

  • serverless-apigw-binary
  • serverless-offline
  • serverless-api-stage
  • serverless-plugin-split-stacks
    Have any suggestions to hunt down the issue?
Serverless: Invoke aws:package:finalize
Serverless: [serverless-plugin-split-stacks]: Summary: 65 resources migrated in to 3 nested stacks
Serverless: [serverless-plugin-split-stacks]:    Resources per stack:
Serverless: [serverless-plugin-split-stacks]:    - (root): 134
Serverless: [serverless-plugin-split-stacks]:    - APINestedStack: 58
Serverless: [serverless-plugin-split-stacks]:    - PermissionsNestedStack: 6
Serverless: [serverless-plugin-split-stacks]:    - VersionsNestedStack: 1
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Invoke aws:common:validate
Serverless: Commencing API Gateway stage configuration
Serverless: API Gateway stage configuration complete
Serverless: Invoke aws:deploy:deploy
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (59.54 MB)...
Serverless: Validating template...
 
  Error --------------------------------------------------
 
  The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template

@dougmoscrop
Copy link
Owner

Well that was quick!

@dougmoscrop dougmoscrop reopened this Feb 8, 2018
@dougmoscrop
Copy link
Owner

And just as quick: https://github.com/leftclickben/serverless-api-stage/blob/master/src/index.js#L7

It is injecting resources in deploy phase.

@skylarmb
Copy link

skylarmb commented Feb 9, 2018

@dougmoscrop thanks for the help. We resolved this by forking that plugin and changing that line to 'before:package:finalize':

https://github.com/headnote/serverless-api-stage

We did run into another issue with your latest version (1.4.0) though, issue here: #27

1.3.2 is working fine 👍

@Rapol
Copy link

Rapol commented Feb 13, 2018

I dont know if I should revive this thread, also, dont know if I should post the issue under the split-stacks or documentation plugin but you've been really helpful (thanks!).

I think I have found another bug between the plugins since I was able to deploy our serverless project before adding the split-stacks. It really is not much of a big deal since I found a workaround (took me some time to finally nail down the problem). I posted the issue under the PR fix for the documentation plugin.

deliveryhero/serverless-aws-documentation#69 (comment)

@ghost
Copy link

ghost commented Apr 25, 2018

I am seeing the same issue:

plugins:

  • serverless-domain-manager
  • serverless-plugin-split-stacks
  • serverless-plugin-webpack
  • serverless-plugin-deploy-environment

Serverless: Excluding development dependencies...
Serverless: [serverless-plugin-split-stacks]: Summary: 78 resources migrated in to 3 nested stacks
Serverless: [serverless-plugin-split-stacks]:    Resources per stack:
Serverless: [serverless-plugin-split-stacks]:    - (root): 117
Serverless: [serverless-plugin-split-stacks]:    - APINestedStack: 22
Serverless: [serverless-plugin-split-stacks]:    - PermissionsNestedStack: 28
Serverless: [serverless-plugin-split-stacks]:    - VersionsNestedStack: 28
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.............................................................................................................................................................................................
Serverless: Operation failed!
 
  Serverless Error ---------------------------------------
 
  An error occurred: VersionsNestedStack - Embedded stack [...] was not successfully created: The following resource(s) failed to create: ...

Any idea how I can address this?

@AndrewFarley
Copy link

AndrewFarley commented Jun 11, 2018

+1, have this issue when also using serverless-aws-documentation. Commenting it out temporarily fixed that error, but then also I still can't deploy with a different error...

  An error occurred: ApiGatewayDeployment1528719760739 - No integration defined for method (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 5b41d40d-6d72-11e8-8c64-13bb0bc179fe).

kcijezie-wedge added a commit to kcijezie-wedge/serverless-domain-manager that referenced this issue Aug 24, 2018
@simlu
Copy link

simlu commented Sep 8, 2018

Using

  - serverless-plugin-split-stacks
  - serverless-domain-manager

getting the same error

The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template

Which plugin is doing something bad here?

Reference: amplify-education/serverless-domain-manager#120

@Nilos
Copy link

Nilos commented Jan 4, 2019

If anyone else runs into this error there is a simple fix:
Add a stacks-map.js to your serverless root directory with the following content:

/*
  DANGER!
  Using this file incorrectly can delete resources
*/

module.exports = {
  'AWS::ApiGateway::Resource': false,
  'AWS::ApiGateway::RestApi': false,
};

This way the ApiGatewayRestApi is not moved into a nested stack and can still be accessed by serverless-domain-manager and related

@wcamarao
Copy link

This is only an issue if using perType strategy. Disabling it explicitly in favour of perFunction works perfectly fine:

  splitStacks:
    perFunction: true
    perType: false

I know this might not be an option if you manage foundational infra using cfn on sls. In our case this is not an issue because we manage foundational infra using terraform.

@dougmoscrop I was confused at first because the readme says perFunction takes precedence over perType. You might want to highlight perType still applies to other resources.

@dougmoscrop
Copy link
Owner

Yep I can see how that would be confusing

@jamesallardice
Copy link

I just ran into this issue and thought it might be worth detailing why it happened here in case it helps anyone else. In my case I am trying to split a fairly large existing stack with a lot of custom resources and plugins (a couple of which depend on the ApiGatewayRestApi resource) which cannot be replaced (such as Cognito user pools, the replacement of which results in unrecoverable data loss) so I've gone down the perFunction route.

Because I have a lot of existing functions and can't see a way to get existing resources related to those functions into the nested stacks, I temporarily removed all of the functions from serverless.yml, and added a single new function as a placeholder, with the intention of subsequently removing that function and putting the original ones back in. Deploying the stack at this point resulted in the error discussed in this issue.

The cause in my case was the fact that my placeholder function did not have an http event in its definition, which understandably means the Serverless Framework does not need to create an ApiGatewayRestApi resource. I resolved the issue by providing an http event to the function so that the resource was created as before.

@StevenPMX
Copy link

I just ran into this issue and thought it might be worth detailing why it happened here in case it helps anyone else. In my case I am trying to split a fairly large existing stack with a lot of custom resources and plugins (a couple of which depend on the ApiGatewayRestApi resource) which cannot be replaced (such as Cognito user pools, the replacement of which results in unrecoverable data loss) so I've gone down the perFunction route.

Because I have a lot of existing functions and can't see a way to get existing resources related to those functions into the nested stacks, I temporarily removed all of the functions from serverless.yml, and added a single new function as a placeholder, with the intention of subsequently removing that function and putting the original ones back in. Deploying the stack at this point resulted in the error discussed in this issue.

The cause in my case was the fact that my placeholder function did not have an http event in its definition, which understandably means the Serverless Framework does not need to create an ApiGatewayRestApi resource. I resolved the issue by providing an http event to the function so that the resource was created as before.

That helped me a lot. In a few words:

I was tryng to deploy an empty stack with no functions. So I added a demo function and it worked!

@SrushithR
Copy link

SrushithR commented Jan 9, 2021

Hi @dougmoscrop, I am using the following plugins:

  • serverless-python-requirements

along with the split stacks plugin and suddenly from the last couple of days, I am getting this error - Error: The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi]

Update - The deployments are only failing for the latest version, downgrading to V1.9.3 is working fine

@alamrezoanul
Copy link

alamrezoanul commented Apr 11, 2024

Hi @dougmoscrop good day!
I'm using the latest version of the plugin but getting the same error. I've been stuck for 3 weeks now. Any help would be greatly appreciated since production server is getting affected now.
Here is the actual scenario:
I've a root production stack which has around 1400 resources, it worked until 28th of March this year and then after that it stopped working by throwing an error: Circular dependency. . at that point, I stopped deploying that stack. also I took the last good version of my project but still getting the same error :(
As ar result, I tried to deploy to a new stack, and here i'm getting this error: "Unresolved resource dependencies...."
any help possible?

@dougmoscrop
Copy link
Owner

Are you saying that this started with the latest version of this library? Have you tried locking to a previous version?

@alamrezoanul
Copy link

Hello, @dougmoscrop - Thanks a lot for your quick reply. actually yes, I locked with a previous version, but since still was getting circular dependency error, I upgraded to latest version and then many time it worked. suddenly it isn't!

@dougmoscrop
Copy link
Owner

Does your stack .json contain sensitive information, or can you share it? Can you share details about the full error message?

@alamrezoanul
Copy link

hello @dougmoscrop Dough - sorry for being late response. Actually i was trying something and I managed to get rid of that error but now i'm getting a new error which is "Error: Missing required key 'restApiId' in params". Could you help please? Basically if possible, could you share your email which you monitor regularly so that we can have a back and forth in email? or your skype?

@alamrezoanul
Copy link

Hi @dougmoscrop - i'm again getting the error: Unresolved resource dependencies .
Could you please get back to me?

@alamrezoanul
Copy link

hello @dougmoscrop - need help please, i'm stuck from 3 weeks as of now and please let me know what files I need to share...

@dougmoscrop
Copy link
Owner

I can't provide the level of support you want, but the error message should tell you what resources are involved. Then you look at the .JSON files in the .serverless directory

Further, there has to be some new resources you're adding or changed config which prevents you from deploying - something changed since you last deployed. I would undo that change, and then start looking at deploying a second entire app that reuses resources from the first stack

Post the error message

@alamrezoanul
Copy link

alamrezoanul commented Apr 15, 2024

Hi @dougmoscrop - Thanks for your reply! I've tried to deploy as you said. the last good code to a new stack. Following are the errors now:
× Stack reqfast-api-v2-sls3-1-prod failed to deploy (534s)
Environment: win32, node 18.19.1, framework 3.38.0 (local), plugin 7.2.3, SDK 4.5.1
Credentials: Local, "reqfast" profile
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues

Error:
CREATE_FAILED: UsersPostModel (AWS::ApiGateway::Model)
Resource handler returned message: "Too Many Requests (Service: ApiGateway, Status Code: 429, Request ID: 35806ff6-8468-4ea8-818c-c2a1af984a81)" (RequestToken: ca67e546-d44d-0ba6-b02c-284f0192f4a0, HandlerErrorCode: InternalFailure)

@dougmoscrop
Copy link
Owner

You're being rate limited by the AWS API Gateway APIs.

You can try this https://github.com/dougmoscrop/serverless-plugin-split-stacks?tab=readme-ov-file#concurrency but I didn't write that feature. You might want lower numbers of concurrency too

I would use http proxy not rest APIs.

@alamrezoanul
Copy link

@dougmoscrop - let me try
stackConcurrency: 5 # Controls if enabled and how much stacks are deployed in parallel. Disabled if absent.
resourceConcurrency: 10 # Controls how much resources are deployed in parallel. Disabled if absent.

@alamrezoanul
Copy link

and also - http proxy you mean the single function implementation?

@dougmoscrop
Copy link
Owner

Yes

@alamrezoanul
Copy link

Ohh that won't be possible in this case. the stakeholders don't want that

@alamrezoanul
Copy link

@dougmoscrop - now getting this error:
**× Stack reqfast-api-v2-sls3-1-prod failed to deploy (342s)
Environment: win32, node 18.19.1, framework 3.38.0 (local), plugin 7.2.3, SDK 4.5.1
Credentials: Local, "reqfast" profile
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues

Error:
The CloudFormation template is invalid: Circular dependency between resources: [10NestedStack, 17NestedStack, 20NestedStack, ApiGatewayDeployment1713218042990, 1NestedStack, 16NestedStack, 11NestedStack, 18NestedStack, 6NestedStack, 8NestedStack, 5NestedStack, 14NestedStack, 3NestedStack]**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests