localstack icon indicating copy to clipboard operation
localstack copied to clipboard

Create new stack results in DescribeStack "Stack not found" exception

Open mikebrules opened this issue 9 years ago • 12 comments

Hello, I'm trying to use the CloudFormation endpoint to create a simple Dynamo stack. My create-stack request is failing when trying to run the describe-stacks operation with this

An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack 
 with id testdb does not exist Traceback (most recent call last):

Any idea why the create-stack is failing when not finding a stack of that name?

mikebrules avatar Sep 15 '17 08:09 mikebrules

I'm facing the same issue when creating a Lambda & Api Gateway stack.

I've managed to get passed this error by initially creating a stack with no resources.

awslocal cloudformation create-stack --stack-name test --template-body '{"Resources":{}}'

{
    "StackId": "arn:aws:cloudformation:us-east-1:123456789:stack/test/3172f176-5d74-4831-8d8b-beb0b699d9e4"
}

However, I still haven't successfully created my stack due to another error due to the stack to be updated having 0 resources and localstack assuming there is a resource.

2017-09-19T11:40:42:ERROR:localstack.services.generic_proxy: Error forwarding request: list index out of range Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/localstack/services/generic_proxy.py", line 194, in forward
    path=path, data=data, headers=forward_headers, response=response)
  File "/usr/local/lib/python3.6/site-packages/localstack/services/cloudformation/cloudformation_listener.py", line 180, in return_response
    template_deployer.deploy_template(template, req_data.get('StackName')[0])
  File "/usr/local/lib/python3.6/site-packages/localstack/utils/cloudformation/template_deployer.py", line 468, in deploy_template
    resource['__details__'] = stack_resources[0]
IndexError: list index out of range

Adding a dummy resource to the initial create triggers the initial error with 'DescribeResources'

awslocal cloudformation create-stack --stack-name test1 --template-body '{"Resources":{"Test":{}}}'

2017-09-19T11:43:12:ERROR:localstack.services.generic_proxy: Error forwarding request: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id test1 does not exist Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/localstack/services/generic_proxy.py", line 194, in forward
    path=path, data=data, headers=forward_headers, response=response)
  File "/usr/local/lib/python3.6/site-packages/localstack/services/cloudformation/cloudformation_listener.py", line 180, in return_response
    template_deployer.deploy_template(template, req_data.get('StackName')[0])
  File "/usr/local/lib/python3.6/site-packages/localstack/utils/cloudformation/template_deployer.py", line 467, in deploy_template
    stack_resources = describe_stack_resources(stack_name, resource_id)
  File "/usr/local/lib/python3.6/site-packages/localstack/utils/cloudformation/template_deployer.py", line 204, in describe_stack_resources
    resources = client.describe_stack_resources(StackName=stack_name, LogicalResourceId=logical_resource_id)
  File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 253, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 557, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id test1 does not exist

hutchy2570 avatar Sep 19 '17 10:09 hutchy2570

As a test, I recreated the integration test for create-stack

awslocal cloudformation create-stack --stack-name test-cf-stack-1 --template-body https://raw.githubusercontent.com/localstack/localstack/master/tests/integration/templates/template1.yaml

That seems to create the stack successfully.

2017-09-19T11:48:28:WARNING:localstack.utils.cloudformation.template_deployer: Unexpected error retrieving details for resource AWS::SQS::Queue: 'QueueUrls' Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/localstack/utils/cloudformation/template_deployer.py", line 280, in retrieve_resource_details
    item.endswith('/%s' % resource_id), queues['QueueUrls']))
KeyError: 'QueueUrls'
 - {'Type': 'AWS::SQS::Queue', 'Properties': {'QueueName': 'cf-test-queue-1'}, '__details__': {'StackName': 'test-cf-stack-1', 'StackId': 'arn:aws:cloudformation:us-east-1:123456789:stack/test-cf-stack-1/69aa4ab4-bb3c-4cc4-94b8-d161ed884bc1', 'LogicalResourceId': 'SQSQueue', 'PhysicalResourceId': 'cf-test-queue-1', 'ResourceType': 'AWS::SQS::Queue', 'Timestamp': datetime.datetime(2010, 7, 27, 22, 27, 28, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_COMPLETE'}} {'StackName': 'test-cf-stack-1', 'StackId': 'arn:aws:cloudformation:us-east-1:123456789:stack/test-cf-stack-1/69aa4ab4-bb3c-4cc4-94b8-d161ed884bc1', 'LogicalResourceId': 'SQSQueue', 'PhysicalResourceId': 'cf-test-queue-1', 'ResourceType': 'AWS::SQS::Queue', 'Timestamp': datetime.datetime(2010, 7, 27, 22, 27, 28, tzinfo=tzutc()), 'ResourceStatus': 'CREATE_COMPLETE'}
2017-09-19T11:48:28:INFO:boto3.resources.action: Calling s3:create_bucket with {'Bucket': 'cf-test-bucket-1', 'ACL': 'PublicRead'}
2017-09-19T11:48:28:INFO:boto3.resources.action: Calling sqs:create_queue with {'QueueName': 'cf-test-queue-1'}

But if I change the stack name, it blows up with the stack name does not exist error awslocal cloudformation create-stack --stack-name test-cf-stack-2 --template-body https://raw.githubusercontent.com/localstack/localstack/master/tests/integration/templates/template1.yaml

2017-09-19T11:50:47:ERROR:localstack.services.generic_proxy: Error forwarding request: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id test-cf-stack-2 does not exist Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/localstack/services/generic_proxy.py", line 194, in forward
    path=path, data=data, headers=forward_headers, response=response)
  File "/usr/local/lib/python3.6/site-packages/localstack/services/cloudformation/cloudformation_listener.py", line 180, in return_response
    template_deployer.deploy_template(template, req_data.get('StackName')[0])
  File "/usr/local/lib/python3.6/site-packages/localstack/utils/cloudformation/template_deployer.py", line 467, in deploy_template
    stack_resources = describe_stack_resources(stack_name, resource_id)
  File "/usr/local/lib/python3.6/site-packages/localstack/utils/cloudformation/template_deployer.py", line 204, in describe_stack_resources
    resources = client.describe_stack_resources(StackName=stack_name, LogicalResourceId=logical_resource_id)
  File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 253, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 557, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id test-cf-stack-2 does not exist

hutchy2570 avatar Sep 19 '17 10:09 hutchy2570

thanks @hutchy2570 let me see if I can create an empty stack sucessfully as per your first post. I'm not sure if it related, but I had another issue I reported which was Lambdas reporting they did not exist when they did, which was actually being caused by an error in the code itself (node). I wonder if the "Does not exist" is a similar thing - the error is disguising the actual issue?

mikebrules avatar Sep 19 '17 11:09 mikebrules

hi @hutchy2570 I have managed to successfully create a stack, as long as it doesn't have an functions in it. I am able to create dynamo tables successfully, except, for example, using a Fn::Join with a parameter which breaks the stack

 Invalid type for parameter TableName, value: {u'Fn::Join': [u'-', [{u'Ref': u'Environment'}, 
 u'users']]}, type: <type 'dict'>, valid types: <type 'basestring'>

Otherwise, it works well. Not sure what was causing the earlier issue. I'll keep looking

mikebrules avatar Sep 21 '17 11:09 mikebrules

I am experiencing issues with cloud formation as well. I'm using docker latest.

$ docker pull localstack/localstack
Using default tag: latest
latest: Pulling from localstack/localstack
Digest: sha256:642e21f53c8d330e62f4eb4b29b6b7fab80d4431597e8f60a230da138e948c4c
Status: Image is up to date for localstack/localstack:latest

I am executing and it just hangs:

aws cloudformation create-stack \                                                                                                                                                                                                                  ⏎
    --stack-name test-cf-stack-1 \
    --template-body https://raw.githubusercontent.com/localstack/localstack/master/tests/integration/templates/template1.yaml \
    --endpoint-url=http://localhost:4581

This is the docker output:

aws    | 2017-10-10T20:32:21:ERROR:localstack.services.generic_proxy: Error forwarding request: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id test-cf-stack-1 does not exist Traceback (most recent call last):
aws    |   File "/opt/code/localstack/localstack/services/generic_proxy.py", line 194, in forward
aws    |     path=path, data=data, headers=forward_headers, response=response)
aws    |   File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_listener.py", line 180, in return_response
aws    |     template_deployer.deploy_template(template, req_data.get('StackName')[0])
aws    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 484, in deploy_template
aws    |     stack_resources = describe_stack_resources(stack_name, resource_id)
aws    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 218, in describe_stack_resources
aws    |     resources = client.describe_stack_resources(StackName=stack_name, LogicalResourceId=logical_resource_id)
aws    |   File "/opt/code/localstack/.venv/lib/python2.7/site-packages/botocore/client.py", line 310, in _api_call
aws    |     return self._make_api_call(operation_name, kwargs)
aws    |   File "/opt/code/localstack/.venv/lib/python2.7/site-packages/botocore/client.py", line 599, in _make_api_call
aws    |     raise error_class(parsed_response, operation_name)
aws    | ClientError: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id test-cf-stack-1 does not exist
aws    | 

Affects docker image latest, 0.8.1 and 0.7.5.

trungie avatar Oct 10 '17 20:10 trungie

Same issues here. Using a few different functions in my template.

samgurtman-zz avatar Oct 23 '17 23:10 samgurtman-zz

I've had the same issue when using an example from issue #172 and adding parameters to it.

command: awslocal cloudformation create-stack --template-body file://simple.json --stack-name simple-stack-with-params --parameters ParameterKey=prefix,ParameterValue=local

template:

    {
      "AWSTemplateFormatVersion": "2010-09-09",
      "Parameters": {
        "Prefix": {
          "Type": "String"
        }
      },  
      "Resources": {
        "TableCustomFieldsCustomFields": {
          "Type": "AWS::DynamoDB::Table",
          "Properties": {
            "AttributeDefinitions": [
              {
                "AttributeName": "id",
                "AttributeType": "S"
              }
            ],
            "KeySchema": [
              {
                "AttributeName": "id",
                "KeyType": "HASH"
              }
            ],
            "ProvisionedThroughput": {
              "ReadCapacityUnits": 5,
              "WriteCapacityUnits": 5
            },
            "TableName": "myTable"
          }
        }
      }
    }

error

ERROR:localstack.services.generic_proxy: Error forwarding request: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id simple-stack-with-params does not exist Traceback (most recent call last):
  File "/Users/christopher.taormina/src/localstack/localstack/services/generic_proxy.py", line 185, in forward
    path=path, data=data, headers=forward_headers, response=response)
  File "/Users/christopher.taormina/src/localstack/localstack/services/cloudformation/cloudformation_listener.py", line 183, in return_response
    template_deployer.deploy_template(template, req_data.get('StackName')[0])
  File "/Users/christopher.taormina/src/localstack/localstack/utils/cloudformation/template_deployer.py", line 486, in deploy_template
    stack_resources = describe_stack_resources(stack_name, resource_id)
  File "/Users/christopher.taormina/src/localstack/localstack/utils/cloudformation/template_deployer.py", line 218, in describe_stack_resources
    resources = client.describe_stack_resources(StackName=stack_name, LogicalResourceId=logical_resource_id)
  File "/Users/christopher.taormina/src/localstack/.venv/lib/python2.7/site-packages/botocore/client.py", line 310, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/christopher.taormina/src/localstack/.venv/lib/python2.7/site-packages/botocore/client.py", line 599, in _make_api_call
    raise error_class(parsed_response, operation_name)
ClientError: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id simple-stack-with-params does not exist

taormania avatar Oct 31 '17 16:10 taormania

Thanks for reporting @taormania @hutchy2570 @mikebrules @samgurtman . Turns out that the create-stack command with the Prefix parameter results in an upstream 400 error, because the parameter matching is case sensitive (Prefix vs prefix). This should be fixed in #444, the upstream 400 error is now forwarded to the client.

@taormania Can you please give it a try with the latest version by changing the argument to ParameterKey=Prefix . Thanks

whummer avatar Nov 05 '17 05:11 whummer

@whummer that works for me. Thanks.

taormania avatar Nov 06 '17 14:11 taormania

Closing this issue. Please re-open or comment here if the problem persists. Thanks

whummer avatar Nov 17 '17 13:11 whummer

Thank you for the effort guys. I am stuck with the error that I am seeing all over the place.

Pulled the latest image, and then tried the following

aws cloudformation create-stack --profile dev --stack-name test-cf-stack-1 --template-body https://raw.githubusercontent.com/localstack/localstack/master/tests/integration/templates/template1.yaml --endpoint-url=http://localhost:4581

Got the same error: ClientError: An error occurred (ValidationError) when calling the DescribeStackResources operation: Stack with id test-cf-stack-1 does not exist

gsaadeh avatar Jul 23 '18 06:07 gsaadeh

@gsaadeh add a --region "region where the stack is located" to the command to fix the error.

ZeusGolohor avatar Jul 30 '22 02:07 ZeusGolohor