localstack: aws cp fails to upload file to S3 bucket

Viewed 3092

I launched a Docker container for the image localstack/localstack:0.12.9.1. I opened the internal shell of this container by the command:

docker exec -it <container-name> sh

The next thing I wanted to do is to upload a file to S3 bucket.

I executed the command:

aws s3 cp /my-file.txt s3://my-bucket/. --region local --endpoint-url=http://local
stack:4566

and I got the error message:

upload failed: ../../../my-file.txt to s3://my-bucket/. An error occurred (500) when calling the PutObject operation (reached max retries: 4): Internal Server Error

To be sure that this bucket exists, I executed the command:

aws s3api list-buckets --region local --endpoint-url=http://localstack:4566

and I got:

{
    "Buckets": [
        {
            "Name": "my-bucket",
            "CreationDate": "2021-05-14T14:23:03.000Z"
        }
    ],
    "Owner": {
        "DisplayName": "webfile",
        "ID": "bcaf1ffd86f41161ca5fb16fd081034f"
    } 
}

So the problem is not that the bucket is missing.

Do you know why I cannot upload file to S3?

2 Answers

Did you also make sure the file /my-file.txt exists? since it should be located inside the container

There have been some changes/fixes with regards to s3. Did you also try with the localstack/localstack:latest image?

As a workaround you can open port 4566 and interact with it from outside the container, which should work. This also saves you from copying files into the container.

You need to create the folder inside bucket & copy the file inside the folder

aws s3api put-object --bucket my-bucket --key data/

aws s3 cp /my-file.txt s3://my-bucket/data/ --region local \
                             --endpoint-url=http://localstack:4566
Related