Lambda S3 "NoSuchBucket" error

When the endpoint of an API Gateway is called, it routes the root directory to a lambda. Inside of the lambda code, it calls an S3 bucket for resources.

The S3 bucket exists, and shows in the CLI.

However, when called, the lambda produces this error:

[2024/01/02/[$LATEST]3c62da480c7130f56e469c69da452eb0] 2024-01-02T19:03:09.988Z f6eb8720-f7cd-4f7f-a11d-1a723716583f INFO Error getting page from S3: NoSuchBucket: The specified bucket does not exist

Initially, I thought the issue could have been permissions based, but in the Terraform configuration, the permissions are clearly defined and assigned to the lambda.

module “api_gateway_lambda” {
source = “terraform-aws-modules/lambda/aws”
function_name = “${var.prefix}-api-gateway-lambda”
description = “API Gateway Lambda Function”
handler = “${var.client_name}-missingindex/index.handler”
runtime = var.lambda_runtime
timeout = var.lambda_timeout
memory_size = var.lambda_memory_size
create_package = false
local_existing_package = “${var.client_name}-missingindex.zip”
policy = “arn:aws:iam::aws:policy/AmazonAPIGatewayInvokeFullAccess”

environment_variables = {
“REDIS_ENDPOINT” = var.redis_env
}
vpc_security_group_ids = [
var.redis_sg
]
vpc_subnet_ids = [
var.vpc_private_subnets[0],
var.vpc_private_subnets[1],
var.vpc_private_subnets[2]
]
}
resource “aws_lambda_permission” “root_lambda_invocation” {
statement_id = “AllowExecutionFromAPIGateway”
action = “lambda:InvokeFunction”
function_name = module.api_gateway_lambda.lambda_function_name
principal = “apigateway.amazonaws.com

source_arn = “arn:aws:execute-api:${var.region}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.root.id}///*”
}

resource “aws_iam_role_policy” “lambda_s3_policy” {
name = “${var.prefix}-lambda-s3-policy”
role = module.api_gateway_lambda.lambda_role_name
policy = jsonencode({
Version = “2012-10-17”
Statement = [
{
Sid = “VisualEditor0”
Effect = “Allow”
Action = [
“s3:Get*”
]
Resource = [
“arn:aws:s3:::${var.prefix}”,
“arn:aws:s3:::${var.prefix}/*”
]
}
]
})
}

What could I be missing that’s causing this error?

Hi @shaq

Welcome to LocalStack Discuss :wave:

Permissions should not be an issue in LocalStack unless you enforce them using ENFORCE_IAM=1 in LocalStack Pro. See IAM Policy Enforcement.

You can start LocalStack with the configuration DEBUG=1 to get more detailed logging. I recommend looking into the Lambda logs to see whether the SDK is configured properly (endpoint and region).

How does the Lambda function know which S3 bucket to look for given that no bucket information is passed into the Lambda through environment variables?

Cheers,
Joel

Hi @shaq,

I can’t see your Lambda code, but here are a few things to look into that might throw a NoSuchBucket exception:

  • make sure your S3 client is configured correctly and is pointing to the right endpoint.
  • additionally, check if the path is properly constructed. Some issues can stem from searching for a bucket on the wrong path, such as hardcoding it, instead of letting the SDK client build it.

You can find some extra information here on using your preferred language SDK: Developing with Amazon S3 using the AWS SDKs, and explorers - Amazon Simple Storage Service
Extra question: does your configuration work on the real AWS? If so, this changes the perspective that we investigate from.

Best,
Anca

Hi there,

I am getting the same error, even with a Pro plan. I bought that plan to persist the data but it randomly keeps disappearing. not sure if I corrupted my state or something (i make sure to do a graceful docker shutdown all the time), but even an export and reimport doesn’t fix it.

ls-ing into the data folder shows the bucket and its files are all still there, but the API (and the web interface on your cloud web UI) shows no buckets can be found.

How can I fix this? Even after I added a bucket with the same name, it didn’t add a new folder, or found the existing data. it just keeps being empty.

Here is my docker compose snippet:

services:
  localstack:
    image: localstack/localstack-pro
    ports:
      - "127.0.0.1:4566:4566"            # LocalStack Gateway
      - "127.0.0.1:4510-4559:4510-4559"  # external services port range
    environment:
      - DEBUG=${DEBUG-}
      - SERVICES=dynamodb,s3
      - LOCALSTACK_AUTH_TOKEN="ls-redacted"
      - PERSISTENCE=1
    volumes:
      - "localstack_pods:/var/lib/localstack"

volumes:
  localstack_pods: {}

Hi @spaceemotion,

I think there’s a missing puzzle piece here. I just tried what you described (create a bucket with a file in it, shut down the container, start it up again - using that exact docker compose) and I haven’t encountered any issue. Are you trying to access the file in the S3 bucket programmatically or by using any HTTP client? Because if you are, the correct endpoint for S3 is s3.localhost.localstack.cloud:4566. Misconfiguring that will lead to a NoSuchBucket exception thrown by your client.
Additionally, is it possible that you created the S3 resource by using a path relative to the current folder (“./localstack_pods”) and then changed it to a named volume (just “localstack_pods”)? In that case, Docker will create that volume, but it will not contain the data you’re looking for.
You also use “persistence”, “state” and “pods” in your description, and while the concepts are relatively similar, they are different features. If you missed it, this can help clear any misunderstanding: State Management | Docs.
If the tips I mentioned don’t help, please let us know if there are more details.

Best,
Anca

Hi Anca, it is just as puzzling to me, actually.
Only thing I know that could have caused this was to add these two lines to the compose file:

  - SNAPSHOT_SAVE_STRATEGY=SCHEDULED
  - SNAPSHOT_LOAD_STRATEGY=ON_STARTUP

I shut down the container, added the flags and booted it back up - instantly, my S3 requests were failing. I added them cause I saw the following info in the log files:

2024-03-08T14:00:04.895  WARN --- [  MainThread] l.p.snapshot.plugins       : registering ON_REQUEST load strategy: this strategy has known limitations to not restore state correctly for certain services
2024-03-08T14:00:05.348  INFO --- [  MainThread] l.p.snapshot.plugins       : registering SCHEDULED save strategy

here are some shots of the bucket and the web ui:

# ls -al
total 24
drwxr-xr-x 5 root root 4096 Nov 23 22:49 .
drwxr-xr-x 7 root root 4096 Mar  4 18:55 ..
-rw-rw-r-- 1 root root   58 Mar  8 15:34 api_states.json
drwxr-xr-x 2 root root 4096 Mar  8 14:36 dynamodb
drwxr-xr-x 2 root root 4096 Nov 23 22:48 dynamodbstreams
drwxr-xr-x 3 root root 4096 Nov 23 22:49 s3
# cd s3
# ls -al
total 16
drwxr-xr-x 3 root root 4096 Nov 23 22:49 .
drwxr-xr-x 5 root root 4096 Nov 23 22:49 ..
drwxr-xr-x 2 root root 4096 Feb  3 21:41 novelcrafter-novel-storage
-rw-r--r-- 1 root root  259 Mar  7 19:48 store.state
# cd novelcrafter-novel-storage
# ls -al
total 1852
drwxr-xr-x 2 root root   4096 Feb  3 21:41 .
drwxr-xr-x 3 root root   4096 Nov 23 22:49 ..
-rw-r--r-- 1 root root  11209 Mar  7 19:48 codex_2V7wslgVGwSxGwZz3qijvdSFmL8_thumbnails_2Yb2j3g3lp6jHURrhaMOtfqvdYj.jpg_8328f105_null
-rw-r--r-- 1 root root  15489 Mar  7 19:48 codex_2V7wsn9u1ANUmsykasPnmOM8Cja_thumbnails_2Yb2XdAOovH5zKDeKhMa91qQufP.jpg_a87cbdb6_null
-rw-r--r-- 1 root root   9536 Mar  7 19:48 codex_2V7wsocWYLZRElMPmsGZ43S7FRi_thumbnails_2Yb2eVLfruvBjc7Dce00KGvO0P4.jpg_72cfa595_null
-rw-r--r-- 1 root root  14356 Mar  7 19:48 codex_2V7wsq8cdPNpsGLLvy2gbyOySIJ_thumbnails_2Yb2wyZhufLRvqRMgUb0meNHmGm.jpg_da6407d0_null
-rw-r--r-- 1 root root  15448 Mar  7 19:48 codex_2V7wssUIDWU91sbReBJTv9My21h_thumbnails_2Yb2mOnp1g5BhtXCzlE2KZhrQVG.jpg_94dfd15f_null
-rw-r--r-- 1 root root  10812 Mar  7 19:48 codex_2V7xcSGuY8HUUderVU4g5XzsJV8_thumbnails_2Yb2klzO5QaVYOKo7SXODyn09Ir.jpg_41de3eee_null
-rw-r--r-- 1 root root  13350 Mar  7 19:48 codex_2V7yOVf70ixxFUmhgvpX7iB1Ura_thumbnails_2Yb30GBI0yVmkmxVa4nYTm7GEox.jpg_3845d55c_null
-rw-r--r-- 1 root root  15745 Mar  7 19:48 codex_2V7yOX8fjgO8XWN9p9RA1lx0RgO_thumbnails_2Yb33v50nfVP4LCGNTzlw5Gz9gf.jpg_8f671f95_null
-rw-r--r-- 1 root root  15081 Mar  7 19:48 codex_2V7yOZ1Gau4bymogK6uX0suDpbA_thumbnails_2Yb2pZK6BpiaY3y9BtBiK5906T5.jpg_f26b1a49_null
-rw-r--r-- 1 root root  13974 Mar  7 19:48 codex_2V7yObioW6HKOSXHK53cr1uzCrZ_thumbnails_2Yb2cVbVqp7Yi2FrvkGS8cWmVuV.jpg_28a90ce1_null
-rw-r--r-- 1 root root  14560 Mar  7 19:48 codex_2V7zL2zJnnx0wrgNmxi7I4SGX1X_thumbnails_2Yb31sadlQFD0rG9SvOu6rMYFUr.jpg_67556551_null
-rw-r--r-- 1 root root   9962 Mar  7 19:48 codex_2VMB2UfExByp8uB60qNStKtecvH_thumbnails_2Yb3638WOrOukTAVIRRczoJAREP.jpg_0665ea2b_null
-rw-r--r-- 1 root root  14581 Mar  7 19:48 codex_2VMB3O3NmrQ8a2V8h7MBSb3pAdT_thumbnails_2Yb37AYwMtvPxjdtjnQdurlhwnt.jpg_5eab340f_null
-rw-r--r-- 1 root root  21340 Mar  7 19:48 codex_2VMYSRlOCWF2HSjr1jF6zVwB83I_thumbnails_2Yb339hdo04268PbY0RVFjw1Byk.jpg_eef497e7_null
-rw-r--r-- 1 root root  12839 Mar  7 19:48 codex_2VqSZRkY5nBsZZwz2B2x8nBE267_thumbnails_2Yb2Z84oSIsRF7oAUn5JXgaCzcb.jpg_0f88a69f_null
-rw-r--r-- 1 root root  15561 Mar  7 19:48 codex_2VqSbDh6whLGxJGkrhLBE2gLvhQ_thumbnails_2Yb2b52iUfjg6IrQQyBqN6Um5uZ.jpg_e258bb71_null
-rw-r--r-- 1 root root  16649 Mar  7 19:48 codex_2YijqWSv8bH0iwTH4oVCA98JDPz_thumbnails_2Yijrt1BjSsX8XvLo8emLDlWLgi.jpg_536449f6_null
-rw-r--r-- 1 root root  22054 Mar  7 19:48 codex_2YjBpTWxXhfUoK7q4aNY5zt3CsA_thumbnails_2YjBr9MUSpsWfo1IQZx3iYpX3il.jpg_5962c92e_null
-rw-r--r-- 1 root root  10861 Mar  7 19:48 codex_2ZdM1Sr1Nqng6qw8hfxaKkZm97I_thumbnails_2ZdM7yEcKhSjqkq6HcWOCbbJ9fE.jpg_3b3d42b4_null
-rw-r--r-- 1 root root  13331 Mar  7 19:48 codex_2bsGaaqP7UwY8JXAXLtnspwj0Ck_thumbnails_2bsGiEBsNVyMRDox6FeVjRnQEoB.jpg_0f96c703_null
-rw-r--r-- 1 root root  18150 Mar  7 19:48 codex_2bsGaaqP7UwY8JXAXLtnspwj0Ck_thumbnails_2bsGjmOpZ34RiHzjKmA2ARSLdiu.jpg_0b9ba437_null
-rw-r--r-- 1 root root  16799 Mar  7 19:48 codex_2bsGaaqP7UwY8JXAXLtnspwj0Ck_thumbnails_2bsGkh1oPnuZeqcBkSecpG0eT4f.jpg_5f195dba_null
-rw-r--r-- 1 root root 174588 Mar  7 19:48 novels_2V5BBk8BriKklAiZw5eZiEAzNnf_covers_2Yb2APTm4dMyAlYQqBCEJguJo6h.jpg_7bceebf6_null
-rw-r--r-- 1 root root 116301 Mar  7 19:48 novels_2VDkc4NlRNGp8cG56bQbC5cJaCL_covers_2Yb2BLKzsuVaK0g74lEcg2aGfNg.jpg_7a5980da_null
-rw-r--r-- 1 root root 130966 Mar  7 19:48 novels_2VDkyfqmTLwx51NlYw97LUEzxqz_covers_2Yb2CE8cVtoq6TznpsV48QV7RN2.jpg_3e74ef17_null
-rw-r--r-- 1 root root 140761 Mar  7 19:48 novels_2VDl1Kuuj0tgTYcDkIsF6pzrbCq_covers_2Yb2DNRGQdjZYwZRzFdU6x14eQk.jpg_93c24d66_null
-rw-r--r-- 1 root root 136190 Mar  7 19:48 novels_2VDl3hu1Mdh8AIyFzAvEr0CQuIq_covers_2Yb2ELzPkCY5rbyJORNCaxueSwt.jpg_cd87f6b7_null
-rw-r--r-- 1 root root 152069 Mar  7 19:48 novels_2VDlhZPvXHavzrBdSvDYBXoaRMl_covers_2Yb28vPDKzC3G6gAwMeboEdJ1mc.jpg_a9e78fe9_null
-rw-r--r-- 1 root root 115600 Mar  7 19:48 novels_2X5kTy7v9ByJ4iaMxGRvtgmnSfs_covers_2Yb25OGrTfPktInrlm0TL39pHCu.jpg_bac6142a_null
-rw-r--r-- 1 root root 161928 Mar  7 19:48 novels_2X5qAavqgwVXw82dQdYNcwBg7Ma_covers_2Yb27y5k0obpmiZdseUNr7qddMm.jpg_f3c2231e_null
-rw-r--r-- 1 root root 123495 Mar  7 19:48 novels_2XJcHNvpQnfM8etREropV8g0dgB_covers_2ZdMJml6rChioW7jpGm8xlFtuCf.jpg_4e11b6e6_null
-rw-r--r-- 1 root root 129574 Mar  7 19:48 novels_2XM1D4epo6bz1AmiZHrmd32ePm8_covers_2Yb26twevHwa6Ixt1LfJsVmewTx.jpg_cf958469_null
-rw-r--r-- 1 root root 112107 Mar  7 19:48 novels_2Ygos0iwAYsalTz0eJX864IvW7E_covers_2YiTlZDcReQfI9XVD26yfwSOBqx.jpg_a8afa833_null

and my log output:

novelcrafter_localstack_main  | 2024-03-08T15:08:37.472  WARN --- [   asgi_gw_3] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.473  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.473  WARN --- [   asgi_gw_1] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.473  WARN --- [   asgi_gw_4] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.474  WARN --- [   asgi_gw_5] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.474  WARN --- [   asgi_gw_2] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.474  WARN --- [   asgi_gw_0] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.475  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.475  INFO --- [   asgi_gw_4] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.476  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.477  INFO --- [   asgi_gw_2] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.477  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.797  WARN --- [   asgi_gw_3] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.798  WARN --- [   asgi_gw_4] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.798  WARN --- [   asgi_gw_2] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.798  WARN --- [   asgi_gw_1] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.799  WARN --- [   asgi_gw_5] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.799  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.799  WARN --- [   asgi_gw_0] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:37.800  INFO --- [   asgi_gw_4] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.800  INFO --- [   asgi_gw_2] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.800  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.801  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:37.801  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:38.122  WARN --- [   asgi_gw_3] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:38.123  WARN --- [   asgi_gw_2] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:38.123  WARN --- [   asgi_gw_1] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:38.123  INFO --- [   asgi_gw_3] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:38.124  WARN --- [   asgi_gw_5] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:38.124  WARN --- [   asgi_gw_4] l.s.s3.presigned_url       : Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1
novelcrafter_localstack_main  | 2024-03-08T15:08:38.124  INFO --- [   asgi_gw_2] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:38.125  INFO --- [   asgi_gw_1] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:38.125  INFO --- [   asgi_gw_5] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:38.126  INFO --- [   asgi_gw_4] localstack.request.aws     : AWS s3.GetObject => 404 (NoSuchBucket)
novelcrafter_localstack_main  | 2024-03-08T15:08:50.349  INFO --- [read-4 (run)] l.persistence.manager      : Saving state for dynamodb took 1 ms
novelcrafter_localstack_main  | 2024-03-08T15:08:50.349  INFO --- [read-4 (run)] l.p.snapshot.manager       : Saving snapshot to disk took 0.00 seconds
novelcrafter_localstack_main  | 2024-03-08T15:11:37.960  INFO --- [   asgi_gw_4] localstack.request.aws     : AWS dynamodb.Query => 200
novelcrafter_localstack_main  | 2024-03-08T15:11:37.975  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS dynamodb.Query => 200

And I guess that by running awslocal s3api list-buckets in your Terminal you still don’t see your bucket?
Where exactly is the folder that you’re ls-ing into located? Is that on your machine, in the same folder as the docker-compose.yml file or in the container?
Also, how are you accessing the objects in the bucket?

Here is the command output, and it is indeed empty:

{
    "Buckets": [],
    "Owner": {
        "DisplayName": "webfile",
        "ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
    }
}

I just used docker compose exec localstack sh to enter the container, otherwise my compose file is the same as above. The data is living in a volume, but i neither removed orphaned volumes or did anything else. The whole DynamoDB dataset is still there, it’s just S3 that got “corrupted”.

To access the bucket I use the @aws-sdk/s3-presigned-post and @aws-sdk/client-s3 packages.

const s3Configuration: S3ClientConfig = {
  ...(process.env.NODE_ENV === 'development' ? {
    region: process.env.APP_AWS_REGION,
    endpoint: `http://localstack:4566`,
    forcePathStyle: true,
    credentials: {
      accessKeyId: 'test',
      secretAccessKey: 'test'
    },
  } : {}),
};

export const s3 = new S3Client(s3Configuration);

// ---- This is a presign request

const presigned = await createPresignedPost(s3, {
  Bucket: BUCKET_NAME_STORAGE, // this is my bucket name
  Key: key,
  Expires: 60 * 5,
  Fields: {
    'Content-Type': contentType,
  },
});

/// --- this is a data fetch request
const command = new GetObjectCommand({
  Bucket: BUCKET_NAME_STORAGE,
  Key: key,
});

const url = await getSignedUrl(s3, command, {
  signingDate: startOfDay(new Date()),
  // Expire after a week, in seconds
  // We hope that the user will have refreshed the page by then
  expiresIn: 60 * 60 * 24 * 7,
});

So first thing: the endpoint of your S3 client should be https://s3.localhost.localstack.cloud:4566 (Simple Storage Service (S3) | Docs).
However, this doesn’t solve the mystery of the volume behavior. It’s super strange that the state exists in the container but is somehow not detected.
Another thing that comes to mind is a version mismatch: if the persisted state was created with a different version of LocalStack, and then imported into another version, that could cause problems. I just noticed the date for the s3 folder in your container, which says Nov 23. Could that be it?

The container has been recreated on that date, since i switched to LS Pro by then (i think). I did not switch versions between the state corruption. I used the same version since then and only updated yesterday after I lost access to the files.

It’s hard to pinpoint what the issue is here. I asked my colleagues who actually worked on these features and there doesn’t seem to be a clear answer. We don’t know for sure what version you are using, since the docker-compose does not specify one. Using the image without a version in the docker-compose file does not guarantee anything.
You should try pulling localstack/localstack-pro:3.2 and specifying this in your docker-compose file. I was also told that a change in how objects are stored happened in 3.2, but it should not affect the bucket.
The logs when LocalStack starts up could give you an indication if the state is correctly discovered/loaded, but clearly, that is not happening since the bucket is not listed.
It’s probably not what you want to hear, but I would start over with the latest version and all the necessary persistence configurations. Since this is a development & testing tool, the integrity of that data may not always be guaranteed.
Thank you for your prompt responses! Please let us know if you run into this issue again or if you have any other problems.

Thanks for the answer! Is there a way to rebuild the index from the state or something? I know it’s not a lot of files, but…

Edit, these are the two versions of localstack i used:

the one that corrupted the state was:

  • date 2023-11-23
  • hash e2b9cb0
  • version 3.0.1.dev

Apparently some things changed in S3 and persistence in general, in the past months. I don’t know if anything really breaking, but now that you started it with both versions, I don’t think you can recover it, especially since there were changes on how objects are mapped to files. Sorry about that.

Okay, no problem! I found out that i can just bulk-rename the image files since they are still JPGs which i can reassign by hand.

However, I am having issue switching to the localstack.cloud URLs. they simply don’t work for me.

  1. My own DNS protected me against domain rebinding, so I had to add the domains to the allowlist
  2. Even trying to open them in the browser it still won’t show. Maybe because of my setup, since docker is running in linux, while I’m on windows (I’m running this stack via WSL2). “localhost” isn’t the same here in this case. I will stick to the current setup, since that worked.