Skip to content

Commit 92237d4

Browse files
Fix: S3 wrap PutObject into ReadSeeker
1 parent 246ebde commit 92237d4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/handler/forwarder/handler.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,21 @@ func (h *Handler) WriteSQS(ctx context.Context, r io.Reader) error {
109109
key = strings.Trim(h.DestinationURI.Path, "/") + "/" + key
110110
}
111111

112+
// Read the entire content into memory to create a seekable reader
113+
// This allows AWS SDK to retry S3 PutObject operations by rewinding the stream
114+
var body io.ReadSeeker
115+
if r != nil {
116+
data, err := io.ReadAll(r)
117+
if err != nil {
118+
return fmt.Errorf("failed to read message data: %w", err)
119+
}
120+
body = bytes.NewReader(data)
121+
}
122+
112123
_, err = h.S3Client.PutObject(ctx, &s3.PutObjectInput{
113124
Bucket: aws.String(h.DestinationURI.Host),
114125
Key: &key,
115-
Body: r,
126+
Body: body,
116127
ContentType: aws.String("application/x-aws-sqs"),
117128
})
118129
if err != nil {

0 commit comments

Comments
 (0)