Closed
Description
I have this script which is using a package to communicate with s3, and it doesn't work with v3 provider.
package main
import (
"bytes"
"context"
"fmt"
"errors"
_ "github.com/docker/distribution/registry/storage/driver/s3-aws"
"github.com/docker/distribution/registry/storage/driver/factory"
)
func main() {
params := map[string]interface{}{
"name": "s3",
"rootdirectory": "/root",
"regionendpoint": "localhost:4566",
"region": "us-east-2",
"bucket": "store",
"secure": true,
"skipverify": true,
}
store, err := factory.Create("s3", params)
if err != nil {
panic(err)
}
filepath := "/test/test"
fileWriter, err := store.Writer(context.TODO(), filepath, false)
if err != nil {
panic(err)
}
if _, err = fileWriter.Write([]byte("first")); err != nil {
panic(err)
}
fileWriter.Close()
fileWriterAppend, err := store.Writer(context.TODO(), filepath, true)
if err != nil {
panic(err)
}
if _, err = fileWriterAppend.Write([]byte("second")); err != nil {
panic(err)
}
fileWriterAppend.Commit()
fileWriterAppend.Close()
fileContent, err := store.GetContent(context.Background(), filepath)
if err != nil {
panic(err)
}
fmt.Println(string(fileContent))
if string(fileContent) != "firstsecond" {
panic(errors.New("not equal"))
}
fileReader, err := store.Reader(context.Background(), filepath, 0)
if err != nil {
panic(err)
}
buf := new(bytes.Buffer)
buf.ReadFrom(fileReader)
content := buf.String()
if content != "firstsecond" {
panic(errors.New("not equal"))
}
fmt.Println(string(content))
}
This is the output:
firstfirsts
panic: not equal
goroutine 1 [running]:
main.main()
/home/peusebiu/localstack_test/main.go:62 +0x689
With v2 provider, script works as expected:
firstsecond
firstsecond
localstack v3 logs:
LocalStack version: 2.3.2
LocalStack build date: 2023-10-03
LocalStack build git hash: 1bccf790
2023-10-18T11:13:32.915 INFO --- [-functhread6] hypercorn.error : Running on https://0.0.0.0:4566 (CTRL + C to quit)
2023-10-18T11:13:32.915 INFO --- [-functhread6] hypercorn.error : Running on https://0.0.0.0:4566 (CTRL + C to quit)
2023-10-18T11:13:32.993 INFO --- [ MainThread] localstack.utils.bootstrap : Execution of "start_runtime_components" took 605.96ms
Ready.
2023-10-18T11:13:39.549 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CreateBucket => 200
2023-10-18T11:13:41.734 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CreateMultipartUpload => 200
2023-10-18T11:13:41.755 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.UploadPart => 200
2023-10-18T11:13:41.783 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.ListMultipartUploads => 200
2023-10-18T11:13:41.805 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.ListParts => 200
2023-10-18T11:13:41.828 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CompleteMultipartUpload => 200
2023-10-18T11:13:41.848 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CreateMultipartUpload => 200
2023-10-18T11:13:41.869 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.GetObject => 200
2023-10-18T11:13:41.891 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.UploadPart => 200
2023-10-18T11:13:41.914 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CompleteMultipartUpload => 200
2023-10-18T11:13:41.934 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.GetObject => 206
2023-10-18T11:13:54.333 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CreateMultipartUpload => 200
2023-10-18T11:13:54.353 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.UploadPart => 200
2023-10-18T11:13:54.367 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.ListMultipartUploads => 200
2023-10-18T11:13:54.384 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.ListParts => 200
2023-10-18T11:13:54.405 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CompleteMultipartUpload => 200
2023-10-18T11:13:54.425 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CreateMultipartUpload => 200
2023-10-18T11:13:54.446 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.GetObject => 200
Originally posted by @peusebiu in #7769 (comment)