"Stack with id X does not exist" on all sls commands after successful sls remove

10,676

Solution 1

The problem is that the ${cf:...} syntax requires the output of an existing CloudFormation stack and when you have not yet deployed the project, the stack and its outputs do not exist yet.

If you need to access that output from inside the "current" stack, you should look at how the output is defined by Serverless (this example is from one of my projects):

"ServiceEndpoint":{
  "Description": "URL of the service endpoint",
  "Value": {"Fn::Join":["", [
    "https://",
    {"Ref":"ApiGatewayRestApi"},
    ".execute-api.eu-central-1.",
    {"Ref":"AWS::URLSuffix"},"/dev"]]}
}

You can use the same syntax to "generate" that value in your own stack in places where you need it, replacing the dynamic parts with Serverless variables like ${self:provider.region} and ${self:provider.stage}, or whatever your project has chosen to use instead of them. For example, to add it to the Lambda environment:

provider:
  environment:
    SERVICE_ENDPOINT: {"Fn::Join":["", [
      "https://",
      {"Ref":"ApiGatewayRestApi"},
      ".execute-api.${self:provider.region}.",
      {"Ref":"AWS::URLSuffix"},
      "/${self:provider.stage}"]]}

Solution 2

In my case I deleted the cloudformation stack manually and ran sls deploy -s <stage> --force and it worked.

Solution 3

It turns out the offending bit was ${cf:${self:service}-${self:provider.stage}.ServiceEndpoint} in my serverless.yml. Apparently ${cf:...} stuff (or at least that particular case) in serverless.yml fails if main stack doesn't exist, i.e. you haven't deployed yet.

I can't decide if this is sls bug or should I have known better.

Share:
10,676
Tero Tilus
Author by

Tero Tilus

father, mathematician, abstractionist geek and a loudmouth programming craftsman

Updated on August 27, 2022

Comments

  • Tero Tilus
    Tero Tilus over 1 year

    After successfull sls remove all sls commands fail with

    Stack with id X does not exist

    Checked that stack, additional stacks and S3 deployment bucket were deleted. Tried removing .serverless/, but it didn't help.