Skip to content

Commit a9691ec

Browse files
PBM-1474 - Swap AWS s3 v1 with v2 (#1083)
* use v2 sdk * migrate download * change mod * remove v1 * update vendor * update doc for delete * implement logger * resolve deprecated * add check for AES to copy * update retyer Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4d84569 commit a9691ec

File tree

821 files changed

+170992
-133323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

821 files changed

+170992
-133323
lines changed

go.mod

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ go 1.22
55
require (
66
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0
77
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.1
8-
github.com/aws/aws-sdk-go v1.55.5
8+
github.com/aws/aws-sdk-go-v2 v1.33.0
9+
github.com/aws/aws-sdk-go-v2/config v1.29.0
10+
github.com/aws/aws-sdk-go-v2/credentials v1.17.53
11+
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.50
12+
github.com/aws/aws-sdk-go-v2/service/s3 v1.73.0
13+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.8
14+
github.com/aws/smithy-go v1.22.1
915
github.com/docker/docker v27.1.1+incompatible
1016
github.com/fsnotify/fsnotify v1.7.0
1117
github.com/golang/snappy v0.0.4
@@ -30,6 +36,18 @@ require (
3036
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
3137
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
3238
github.com/Microsoft/go-winio v0.6.2 // indirect
39+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
40+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.24 // indirect
41+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28 // indirect
42+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28 // indirect
43+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
44+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.28 // indirect
45+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
46+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.0 // indirect
47+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.9 // indirect
48+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.9 // indirect
49+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.10 // indirect
50+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.9 // indirect
3351
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
3452
github.com/containerd/containerd v1.7.18 // indirect
3553
github.com/containerd/log v0.1.0 // indirect
@@ -47,7 +65,6 @@ require (
4765
github.com/hashicorp/hcl v1.0.0 // indirect
4866
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4967
github.com/jessevdk/go-flags v1.5.0 // indirect
50-
github.com/jmespath/go-jmespath v0.4.0 // indirect
5168
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
5269
github.com/magiconair/properties v1.8.7 // indirect
5370
github.com/mitchellh/mapstructure v1.5.0 // indirect

go.sum

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,44 @@ github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 h1:DzHpqpoJVaC
1818
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
1919
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
2020
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
21-
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
22-
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
21+
github.com/aws/aws-sdk-go-v2 v1.33.0 h1:Evgm4DI9imD81V0WwD+TN4DCwjUMdc94TrduMLbgZJs=
22+
github.com/aws/aws-sdk-go-v2 v1.33.0/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U=
23+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 h1:lL7IfaFzngfx0ZwUGOZdsFFnQ5uLvR0hWqqhyE7Q9M8=
24+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7/go.mod h1:QraP0UcVlQJsmHfioCrveWOC1nbiWUl3ej08h4mXWoc=
25+
github.com/aws/aws-sdk-go-v2/config v1.29.0 h1:Vk/u4jof33or1qAQLdofpjKV7mQQT7DcUpnYx8kdmxY=
26+
github.com/aws/aws-sdk-go-v2/config v1.29.0/go.mod h1:iXAZK3Gxvpq3tA+B9WaDYpZis7M8KFgdrDPMmHrgbJM=
27+
github.com/aws/aws-sdk-go-v2/credentials v1.17.53 h1:lwrVhiEDW5yXsuVKlFVUnR2R50zt2DklhOyeLETqDuE=
28+
github.com/aws/aws-sdk-go-v2/credentials v1.17.53/go.mod h1:CkqM1bIw/xjEpBMhBnvqUXYZbpCFuj6dnCAyDk2AtAY=
29+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.24 h1:5grmdTdMsovn9kPZPI23Hhvp0ZyNm5cRO+IZFIYiAfw=
30+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.24/go.mod h1:zqi7TVKTswH3Ozq28PkmBmgzG1tona7mo9G2IJg4Cis=
31+
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.50 h1:3G2kFXgvcXDVOv+bvvGqqi3oeN5bu3cQETQCDTgHI1M=
32+
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.50/go.mod h1:DUYbS20/A94Pz3YX1h9Y030zzQ5SFpvGMdGNCU61rQw=
33+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28 h1:igORFSiH3bfq4lxKFkTSYDhJEUCYo6C8VKiWJjYwQuQ=
34+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.28/go.mod h1:3So8EA/aAYm36L7XIvCVwLa0s5N0P7o2b1oqnx/2R4g=
35+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28 h1:1mOW9zAUMhTSrMDssEHS/ajx8JcAj/IcftzcmNlmVLI=
36+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.28/go.mod h1:kGlXVIWDfvt2Ox5zEaNglmq0hXPHgQFNMix33Tw22jA=
37+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
38+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
39+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.28 h1:7kpeALOUeThs2kEjlAxlADAVfxKmkYAedlpZ3kdoSJ4=
40+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.28/go.mod h1:pyaOYEdp1MJWgtXLy6q80r3DhsVdOIOZNB9hdTcJIvI=
41+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 h1:iXtILhvDxB6kPvEXgsDhGaZCSC6LQET5ZHSdJozeI0Y=
42+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1/go.mod h1:9nu0fVANtYiAePIBh2/pFUSwtJ402hLnp854CNoDOeE=
43+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.0 h1:pC19SLXdHsfXTvCwy3sHfiACXaSjRkKlOQYnaTk8loI=
44+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.0/go.mod h1:dIW8puxSbYLSPv/ju0d9A3CpwXdtqvJtYKDMVmPLOWE=
45+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.9 h1:TQmKDyETFGiXVhZfQ/I0cCFziqqX58pi4tKJGYGFSz0=
46+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.9/go.mod h1:HVLPK2iHQBUx7HfZeOQSEu3v2ubZaAY2YPbAm5/WUyY=
47+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.9 h1:2aInXbh02XsbO0KobPGMNXyv2QP73VDKsWPNJARj/+4=
48+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.9/go.mod h1:dgXS1i+HgWnYkPXqNoPIPKeUsUUYHaUbThC90aDnNiE=
49+
github.com/aws/aws-sdk-go-v2/service/s3 v1.73.0 h1:sHF4brL/726nbTldh8GGDKFS5LsQ8FwOTKEyvKp9DB4=
50+
github.com/aws/aws-sdk-go-v2/service/s3 v1.73.0/go.mod h1:rGHXqEgGFrz7j58tIGKKAfD1fJzYXeKkN/Jn3eIRZYE=
51+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.10 h1:DyZUj3xSw3FR3TXSwDhPhuZkkT14QHBiacdbUVcD0Dg=
52+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.10/go.mod h1:Ro744S4fKiCCuZECXgOi760TiYylUM8ZBf6OGiZzJtY=
53+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.9 h1:I1TsPEs34vbpOnR81GIcAq4/3Ud+jRHVGwx6qLQUHLs=
54+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.9/go.mod h1:Fzsj6lZEb8AkTE5S68OhcbBqeWPsR8RnGuKPr8Todl8=
55+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.8 h1:pqEJQtlKWvnv3B6VRt60ZmsHy3SotlEBvfUBPB1KVcM=
56+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.8/go.mod h1:f6vjfZER1M17Fokn0IzssOTMT2N8ZSq+7jnNF0tArvw=
57+
github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro=
58+
github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
2359
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
2460
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
2561
github.com/containerd/containerd v1.7.18 h1:jqjZTQNfXGoEaZdW1WwPU0RqSn1Bm2Ay/KJPUuO8nao=
@@ -82,10 +118,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
82118
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
83119
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
84120
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
85-
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
86-
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
87-
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
88-
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
89121
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
90122
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
91123
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -306,7 +338,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
306338
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
307339
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
308340
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
309-
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
310341
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
311342
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
312343
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pbm/compress/compress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"io"
66
"runtime"
77

8-
"github.com/aws/aws-sdk-go/aws"
8+
"github.com/aws/aws-sdk-go-v2/aws"
99
"github.com/golang/snappy"
1010
"github.com/klauspost/compress/s2"
1111
"github.com/klauspost/compress/zstd"

pbm/storage/s3/download.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package s3
22

33
import (
44
"container/heap"
5+
"context"
56
"crypto/md5"
67
"encoding/base64"
78
"fmt"
@@ -12,9 +13,10 @@ import (
1213
"sync/atomic"
1314
"time"
1415

15-
"github.com/aws/aws-sdk-go/aws"
16-
"github.com/aws/aws-sdk-go/aws/awserr"
17-
"github.com/aws/aws-sdk-go/service/s3"
16+
"github.com/aws/aws-sdk-go-v2/aws"
17+
"github.com/aws/aws-sdk-go-v2/service/s3"
18+
"github.com/aws/aws-sdk-go-v2/service/s3/types"
19+
smithyhttp "github.com/aws/smithy-go/transport/http"
1820

1921
"github.com/percona/percona-backup-mongodb/pbm/errors"
2022
"github.com/percona/percona-backup-mongodb/pbm/log"
@@ -188,7 +190,7 @@ type partReader struct {
188190
written int64
189191
chunkSize int64
190192

191-
getSess func() (*s3.S3, error)
193+
getSess func() (*s3.Client, error)
192194
l log.LogEvent
193195
opts *Config
194196
buf []byte // preallocated buf for io.Copy
@@ -207,13 +209,12 @@ func (s *S3) newPartReader(fname string, fsize int64, chunkSize int) *partReader
207209
fname: fname,
208210
fsize: fsize,
209211
chunkSize: int64(chunkSize),
210-
getSess: func() (*s3.S3, error) {
211-
sess, err := s.s3session()
212+
getSess: func() (*s3.Client, error) {
213+
cli, err := s.s3client()
212214
if err != nil {
213215
return nil, err
214216
}
215-
sess.Client.Config.HTTPClient.Timeout = time.Second * 60
216-
return sess, nil
217+
return cli, nil
217218
},
218219
}
219220
}
@@ -379,7 +380,7 @@ func (pr *partReader) worker(buf *arena) {
379380
}
380381
}
381382

382-
func (pr *partReader) retryChunk(buf *arena, s *s3.S3, start, end int64, retries int) (io.ReadCloser, error) {
383+
func (pr *partReader) retryChunk(buf *arena, s *s3.Client, start, end int64, retries int) (io.ReadCloser, error) {
383384
var r io.ReadCloser
384385
var err error
385386

@@ -402,7 +403,7 @@ func (pr *partReader) retryChunk(buf *arena, s *s3.S3, start, end int64, retries
402403
return nil, err
403404
}
404405

405-
func (pr *partReader) tryChunk(buf *arena, s *s3.S3, start, end int64) (io.ReadCloser, error) {
406+
func (pr *partReader) tryChunk(buf *arena, s *s3.Client, start, end int64) (io.ReadCloser, error) {
406407
// just quickly retry w/o new session in case of fail.
407408
// more sophisticated retry on a caller side.
408409
const retry = 2
@@ -425,7 +426,7 @@ func (pr *partReader) tryChunk(buf *arena, s *s3.S3, start, end int64) (io.ReadC
425426
return nil, errors.Wrapf(err, "failed to download chunk %d-%d (of %d) after %d retries", start, end, pr.fsize, retry)
426427
}
427428

428-
func (pr *partReader) getChunk(buf *arena, s *s3.S3, start, end int64) (io.ReadCloser, error) {
429+
func (pr *partReader) getChunk(buf *arena, s *s3.Client, start, end int64) (io.ReadCloser, error) {
429430
getObjOpts := &s3.GetObjectInput{
430431
Bucket: aws.String(pr.opts.Bucket),
431432
Key: aws.String(path.Join(pr.opts.Prefix, pr.fname)),
@@ -436,20 +437,23 @@ func (pr *partReader) getChunk(buf *arena, s *s3.S3, start, end int64) (io.ReadC
436437
if sse != nil && sse.SseCustomerAlgorithm != "" {
437438
getObjOpts.SSECustomerAlgorithm = aws.String(sse.SseCustomerAlgorithm)
438439
decodedKey, err := base64.StdEncoding.DecodeString(sse.SseCustomerKey)
439-
getObjOpts.SSECustomerKey = aws.String(string(decodedKey))
440+
getObjOpts.SSECustomerKey = aws.String(sse.SseCustomerKey)
440441
if err != nil {
441442
return nil, errors.Wrap(err, "SseCustomerAlgorithm specified with invalid SseCustomerKey")
442443
}
443444
keyMD5 := md5.Sum(decodedKey)
444445
getObjOpts.SSECustomerKeyMD5 = aws.String(base64.StdEncoding.EncodeToString(keyMD5[:]))
445446
}
446447

447-
s3obj, err := s.GetObject(getObjOpts)
448+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
449+
defer cancel()
450+
451+
s3obj, err := s.GetObject(ctx, getObjOpts)
448452
if err != nil {
449453
// if object size is undefined, we would read
450454
// until HTTP code 416 (Requested Range Not Satisfiable)
451-
rerr, ok := err.(awserr.RequestFailure) //nolint:errorlint
452-
if ok && rerr.StatusCode() == http.StatusRequestedRangeNotSatisfiable {
455+
var re *smithyhttp.ResponseError
456+
if errors.As(err, &re) && re.Err != nil && re.Response.StatusCode == http.StatusRequestedRangeNotSatisfiable {
453457
return nil, io.EOF
454458
}
455459

@@ -459,8 +463,8 @@ func (pr *partReader) getChunk(buf *arena, s *s3.S3, start, end int64) (io.ReadC
459463
defer s3obj.Body.Close()
460464

461465
if sse != nil {
462-
if sse.SseAlgorithm == s3.ServerSideEncryptionAwsKms {
463-
s3obj.ServerSideEncryption = aws.String(sse.SseAlgorithm)
466+
if sse.SseAlgorithm == string(types.ServerSideEncryptionAwsKms) {
467+
s3obj.ServerSideEncryption = types.ServerSideEncryptionAwsKms
464468
s3obj.SSEKMSKeyId = aws.String(sse.KmsKeyID)
465469
} else if sse.SseCustomerAlgorithm != "" {
466470
s3obj.SSECustomerAlgorithm = aws.String(sse.SseCustomerAlgorithm)

pbm/storage/s3/retryer.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package s3
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/aws/aws-sdk-go-v2/aws"
8+
"github.com/aws/aws-sdk-go-v2/aws/retry"
9+
)
10+
11+
type CustomRetryer struct {
12+
// base is the AWS standard retryer.
13+
base aws.Retryer
14+
15+
// MinBackoff is the minimum delay that will be returned from RetryDelay.
16+
MinBackoff time.Duration
17+
}
18+
19+
func (r CustomRetryer) IsErrorRetryable(err error) bool {
20+
return r.base.IsErrorRetryable(err)
21+
}
22+
23+
func (r CustomRetryer) MaxAttempts() int {
24+
return r.base.MaxAttempts()
25+
}
26+
27+
func (r CustomRetryer) RetryDelay(attempt int, opErr error) (time.Duration, error) {
28+
delay, err := r.base.RetryDelay(attempt, opErr)
29+
if err != nil {
30+
return delay, err
31+
}
32+
33+
if delay < r.MinBackoff {
34+
delay = r.MinBackoff
35+
}
36+
37+
return delay, nil
38+
}
39+
40+
func (r CustomRetryer) GetRetryToken(ctx context.Context, opErr error) (func(error) error, error) {
41+
return r.base.GetRetryToken(ctx, opErr)
42+
}
43+
44+
func (r CustomRetryer) GetInitialToken() func(error) error {
45+
return r.base.GetInitialToken()
46+
}
47+
48+
func NewCustomRetryer(numMaxRetries int, minBackoff, maxBackoff time.Duration) aws.Retryer {
49+
baseRetryer := retry.NewStandard(func(o *retry.StandardOptions) {
50+
// v2's MaxAttempts includes the first attempt, we add 1 to match v1 behavior
51+
o.MaxAttempts = numMaxRetries + 1
52+
o.MaxBackoff = maxBackoff
53+
})
54+
55+
return &CustomRetryer{
56+
base: baseRetryer,
57+
MinBackoff: minBackoff,
58+
}
59+
}

0 commit comments

Comments
 (0)