Reset the state of all resources

Hi. I’m using a localstack for integration testing and trying to reset a state of localstack between tests.
I tried to find /reset HTTP endpoint but it seems like it is not working for me.

Expected behaviour: after calling /reset - reset to initial state and execute /etc/localstack/init/ready.d/init_localstack.sh again.

Can you please help with it. Thank you!

Hi @pwlae,

In order to better correspond with the service they affect, endpoints have been moved.
To reset a state, you should now call /_localstack/state/reset or /_localstack/state/<service>/reset.

2 Likes

Hi @Marcel

Thank you for your reply.
I’m not sure it is working for me for some reason. Both paths return 404 (GET PUT POST DELETE). I use default port 4456.
Also I can’t find reset route and handler in source code master branch.

Are you using LocalStack v2.0+?
I am able to get 200 responses when using:
curl -v --request POST http://localhost:4566/_localstack/state/reset

I use version 2.0.2.dev

# curl -XGET http://localhost:4566/_localstack/health

{"services": {"acm": "available", "apigateway": "available", "cloudformation": "available", "cloudwatch": "available", "config": "available", "dynamodb": "available", "dynamodbstreams": "available", "ec2": "available", "es": "available", "events": "available", "firehose": "available", "iam": "available", "kinesis": "available", "kms": "running", "lambda": "available", "logs": "available", "opensearch": "available", "redshift": "available", "resource-groups": "available", "resourcegroupstaggingapi": "available", "route53": "available", "route53resolver": "available", "s3": "running", "s3control": "available", "secretsmanager": "available", "ses": "available", "sns": "available", "sqs": "available", "ssm": "available", "stepfunctions": "available", "sts": "available", "support": "available", "swf": "available", "transcribe": "available"}, "version": "2.0.2.dev"}

When I send POST to reset endpoint

# curl -v --request POST http://localhost:4566/_localstack/state/reset

...

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 149999 ms for 3 (transfer 0x560608a80110)
* Expire in 200 ms for 4 (transfer 0x560608a80110)
* Connected to localhost (127.0.0.1) port 4566 (#0)
> POST /_localstack/state/reset HTTP/1.1
> Host: localhost:4566
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 404 
< Content-Type: text/plain; charset=utf-8
< Connection: close
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: HEAD,GET,PUT,POST,DELETE,OPTIONS,PATCH
< Access-Control-Allow-Headers: authorization,cache-control,content-length,content-md5,content-type,etag,location,x-amz-acl,x-amz-content-sha256,x-amz-date,x-amz-request-id,x-amz-security-token,x-amz-tagging,x-amz-target,x-amz-user-agent,x-amz-version-id,x-amzn-requestid,x-localstack-target,amz-sdk-invocation-id,amz-sdk-request
< Access-Control-Expose-Headers: etag,x-amz-version-id
< Content-Length: 0
< date: Wed, 19 Apr 2023 13:57:41 GMT
< server: hypercorn-h11
< 
* Closing connection 0

All requests I send from inside localstack container.
Docker image contains only one COPY of init script

FROM localstack/localstack:latest
COPY --chmod=755 ./test/scripts/init_localstack.sh /etc/localstack/init/ready.d/init_localstack.sh

Hi @pwlae,
I just noticed that you are using the community version. Yes, you are right, in the community version this reset state will not work.

Do you refer to these commands? This will restart/kill the entire LocalStack instance.

 curl -v --request POST --header "Content-Type: application/json"  --data '{"action":"restart"}' http://localhost:4566/_localstack/health

 curl -v --request POST --header "Content-Type: application/json"  --data '{"action":"kill"}' http://localhost:4566/_localstack/health