Skip to content

Commit a3a3950

Browse files
authored
upgrade to aws-sdk-go-v2 (#334)
* upgrade to aws-sdk-go-v2 * x * x
1 parent 9ce1181 commit a3a3950

File tree

5 files changed

+101
-50
lines changed

5 files changed

+101
-50
lines changed

base/aws.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package base
22

33
import (
4-
"github.com/aws/aws-sdk-go/aws"
5-
"github.com/aws/aws-sdk-go/aws/session"
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/config"
68
)
79

8-
func GetSession(region string) (sess *session.Session, err error) {
9-
if sess, err = session.NewSession(&aws.Config{
10-
Region: aws.String(region),
11-
}); err != nil {
12-
return nil, err
10+
func GetAWSConfig(ctx context.Context, region string) (aws.Config, error) {
11+
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region))
12+
if err != nil {
13+
return aws.Config{}, err
1314
}
14-
return sess, nil
15+
return cfg, nil
1516
}

base/cloudwatchlogs.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
package base
22

33
import (
4+
"context"
45
"fmt"
56

6-
"github.com/aws/aws-sdk-go/aws"
7-
"github.com/aws/aws-sdk-go/aws/session"
8-
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
7+
"github.com/aws/aws-sdk-go-v2/aws"
8+
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
9+
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
910
)
1011

1112
func GetLatestCloudwatchLogs(region string, logGroupName string) ([]string, error) {
12-
sess, err := session.NewSession(&aws.Config{
13-
Region: aws.String(region),
14-
})
13+
ctx := context.Background()
14+
cfg, err := GetAWSConfig(ctx, region)
1515
if err != nil {
1616
return nil, err
1717
}
18-
svc := cloudwatchlogs.New(sess)
18+
svc := cloudwatchlogs.NewFromConfig(cfg)
1919

20-
streamsIn := new(cloudwatchlogs.DescribeLogStreamsInput).SetDescending(
21-
true).SetLimit(1).SetLogGroupName(logGroupName).SetOrderBy("LastEventTime")
22-
if err = streamsIn.Validate(); err != nil {
23-
return nil, err
20+
descending := true
21+
limit := int32(1)
22+
orderBy := types.OrderByLastEventTime
23+
streamsIn := &cloudwatchlogs.DescribeLogStreamsInput{
24+
Descending: &descending,
25+
Limit: &limit,
26+
LogGroupName: aws.String(logGroupName),
27+
OrderBy: orderBy,
2428
}
25-
streamsOut, err := svc.DescribeLogStreams(streamsIn)
29+
30+
streamsOut, err := svc.DescribeLogStreams(ctx, streamsIn)
2631
if err != nil {
2732
return nil, err
2833
}
@@ -36,19 +41,19 @@ func GetLatestCloudwatchLogs(region string, logGroupName string) ([]string, erro
3641
return nil, fmt.Errorf("Unable to find valid stream %+v", streamsOut.LogStreams[0])
3742
}
3843

39-
eventIn := new(cloudwatchlogs.GetLogEventsInput).SetLogGroupName(
40-
logGroupName).SetLogStreamName(*streamName)
41-
if err := eventIn.Validate(); err != nil {
42-
return nil, err
44+
eventIn := &cloudwatchlogs.GetLogEventsInput{
45+
LogGroupName: aws.String(logGroupName),
46+
LogStreamName: streamName,
4347
}
44-
eventOut, err := svc.GetLogEvents(eventIn)
48+
49+
eventOut, err := svc.GetLogEvents(ctx, eventIn)
4550
if err != nil {
4651
return nil, err
4752
}
4853

4954
res := make([]string, 0, len(eventOut.Events))
5055
for _, event := range eventOut.Events {
51-
if event == nil || event.Message == nil || *event.Message == "" {
56+
if event.Message == nil || *event.Message == "" {
5257
continue
5358
}
5459
res = append(res, *event.Message)

base/email.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package base
22

33
import (
4+
"context"
45
"fmt"
56

6-
"github.com/aws/aws-sdk-go/aws"
7-
"github.com/aws/aws-sdk-go/aws/session"
8-
"github.com/aws/aws-sdk-go/service/ses"
7+
"github.com/aws/aws-sdk-go-v2/aws"
8+
"github.com/aws/aws-sdk-go-v2/service/ses"
9+
"github.com/aws/aws-sdk-go-v2/service/ses/types"
910
)
1011

1112
type Emailer interface {
@@ -23,7 +24,7 @@ type SESEmailer struct {
2324
*DebugOutput
2425
sender string
2526
region string
26-
ses *ses.SES
27+
ses *ses.Client
2728
}
2829

2930
func NewSESEmailer(sender, region string, debugConfig *ChatDebugOutputConfig) *SESEmailer {
@@ -34,33 +35,34 @@ func NewSESEmailer(sender, region string, debugConfig *ChatDebugOutputConfig) *S
3435
}
3536
}
3637

37-
func (e *SESEmailer) getClient() *ses.SES {
38-
var err error
38+
func (e *SESEmailer) getClient() *ses.Client {
3939
if e.ses == nil {
4040
e.Debug("SESEmailer: getting SES client: region: %s", e.region)
41-
var auth *session.Session
42-
if auth, err = GetSession(e.region); err != nil {
41+
ctx := context.Background()
42+
cfg, err := GetAWSConfig(ctx, e.region)
43+
if err != nil {
4344
panic(fmt.Sprintf("unable to authenticate to AWS SES: %s", err.Error()))
4445
}
45-
e.ses = ses.New(auth)
46+
e.ses = ses.NewFromConfig(cfg)
4647
e.Debug("SESEmailer: SES client created")
4748
}
4849
return e.ses
4950
}
5051

5152
func (e *SESEmailer) Send(address, subject, message string) error {
5253
cli := e.getClient()
53-
_, err := cli.SendEmail(&ses.SendEmailInput{
54+
ctx := context.Background()
55+
_, err := cli.SendEmail(ctx, &ses.SendEmailInput{
5456
Source: aws.String(e.sender),
55-
Destination: &ses.Destination{
56-
ToAddresses: aws.StringSlice([]string{address}),
57+
Destination: &types.Destination{
58+
ToAddresses: []string{address},
5759
},
58-
Message: &ses.Message{
59-
Subject: &ses.Content{
60+
Message: &types.Message{
61+
Subject: &types.Content{
6062
Data: aws.String(subject),
6163
},
62-
Body: &ses.Body{
63-
Html: &ses.Content{
64+
Body: &types.Body{
65+
Html: &types.Content{
6466
Data: aws.String(message),
6567
},
6668
},

go.mod

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ go 1.24.0
55
toolchain go1.25.5
66

77
require (
8-
github.com/aws/aws-sdk-go v1.55.7
8+
github.com/aws/aws-sdk-go-v2 v1.41.0
9+
github.com/aws/aws-sdk-go-v2/config v1.32.5
10+
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.62.2
11+
github.com/aws/aws-sdk-go-v2/service/ses v1.34.17
912
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0
1013
github.com/go-sql-driver/mysql v1.9.3
1114
github.com/google/go-github/v31 v31.0.0
@@ -24,6 +27,19 @@ require (
2427

2528
require (
2629
filippo.io/edwards25519 v1.1.0 // indirect
30+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 // indirect
31+
github.com/aws/aws-sdk-go-v2/credentials v1.19.5 // indirect
32+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16 // indirect
33+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.16 // indirect
34+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.16 // indirect
35+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
36+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 // indirect
37+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.16 // indirect
38+
github.com/aws/aws-sdk-go-v2/service/signin v1.0.4 // indirect
39+
github.com/aws/aws-sdk-go-v2/service/sso v1.30.7 // indirect
40+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 // indirect
41+
github.com/aws/aws-sdk-go-v2/service/sts v1.41.5 // indirect
42+
github.com/aws/smithy-go v1.24.0 // indirect
2743
github.com/go-pkgz/expirable-cache v0.1.0 // indirect
2844
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
2945
github.com/google/go-github/v75 v75.0.0 // indirect
@@ -39,7 +55,6 @@ require (
3955
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
4056
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
4157
github.com/hashicorp/go-retryablehttp v0.6.4 // indirect
42-
github.com/jmespath/go-jmespath v0.4.0 // indirect
4358
github.com/kr/text v0.2.0 // indirect
4459
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
4560
github.com/pmezard/go-difflib v1.0.0 // indirect

go.sum

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,40 @@ cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSR
55
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
66
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
77
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
8-
github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE=
9-
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
8+
github.com/aws/aws-sdk-go-v2 v1.41.0 h1:tNvqh1s+v0vFYdA1xq0aOJH+Y5cRyZ5upu6roPgPKd4=
9+
github.com/aws/aws-sdk-go-v2 v1.41.0/go.mod h1:MayyLB8y+buD9hZqkCW3kX1AKq07Y5pXxtgB+rRFhz0=
10+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 h1:489krEF9xIGkOaaX3CE/Be2uWjiXrkCH6gUX+bZA/BU=
11+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4/go.mod h1:IOAPF6oT9KCsceNTvvYMNHy0+kMF8akOjeDvPENWxp4=
12+
github.com/aws/aws-sdk-go-v2/config v1.32.5 h1:pz3duhAfUgnxbtVhIK39PGF/AHYyrzGEyRD9Og0QrE8=
13+
github.com/aws/aws-sdk-go-v2/config v1.32.5/go.mod h1:xmDjzSUs/d0BB7ClzYPAZMmgQdrodNjPPhd6bGASwoE=
14+
github.com/aws/aws-sdk-go-v2/credentials v1.19.5 h1:xMo63RlqP3ZZydpJDMBsH9uJ10hgHYfQFIk1cHDXrR4=
15+
github.com/aws/aws-sdk-go-v2/credentials v1.19.5/go.mod h1:hhbH6oRcou+LpXfA/0vPElh/e0M3aFeOblE1sssAAEk=
16+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16 h1:80+uETIWS1BqjnN9uJ0dBUaETh+P1XwFy5vwHwK5r9k=
17+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16/go.mod h1:wOOsYuxYuB/7FlnVtzeBYRcjSRtQpAW0hCP7tIULMwo=
18+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.16 h1:rgGwPzb82iBYSvHMHXc8h9mRoOUBZIGFgKb9qniaZZc=
19+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.16/go.mod h1:L/UxsGeKpGoIj6DxfhOWHWQ/kGKcd4I1VncE4++IyKA=
20+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.16 h1:1jtGzuV7c82xnqOVfx2F0xmJcOw5374L7N6juGW6x6U=
21+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.16/go.mod h1:M2E5OQf+XLe+SZGmmpaI2yy+J326aFf6/+54PoxSANc=
22+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk=
23+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc=
24+
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.62.2 h1:U7ATBzpyD+A3IxzwKUL+meioIs3HO+/eyxghGTy6bkY=
25+
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.62.2/go.mod h1:ESQxVIp7hs1MdsdEF4KITf65SfM3fh/EEiYi+s0S/pE=
26+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 h1:0ryTNEdJbzUCEWkVXEXoqlXV72J5keC1GvILMOuD00E=
27+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4/go.mod h1:HQ4qwNZh32C3CBeO6iJLQlgtMzqeG17ziAA/3KDJFow=
28+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.16 h1:oHjJHeUy0ImIV0bsrX0X91GkV5nJAyv1l1CC9lnO0TI=
29+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.16/go.mod h1:iRSNGgOYmiYwSCXxXaKb9HfOEj40+oTKn8pTxMlYkRM=
30+
github.com/aws/aws-sdk-go-v2/service/ses v1.34.17 h1:XR7CtY988tck2Bhuy1JP4FsV8z0OAwjuh+gb7nAy8/M=
31+
github.com/aws/aws-sdk-go-v2/service/ses v1.34.17/go.mod h1:2CspeTVldnJdRixX36SzTZuoIpjyKlfeXyB7/JB5KGk=
32+
github.com/aws/aws-sdk-go-v2/service/signin v1.0.4 h1:HpI7aMmJ+mm1wkSHIA2t5EaFFv5EFYXePW30p1EIrbQ=
33+
github.com/aws/aws-sdk-go-v2/service/signin v1.0.4/go.mod h1:C5RdGMYGlfM0gYq/tifqgn4EbyX99V15P2V3R+VHbQU=
34+
github.com/aws/aws-sdk-go-v2/service/sso v1.30.7 h1:eYnlt6QxnFINKzwxP5/Ucs1vkG7VT3Iezmvfgc2waUw=
35+
github.com/aws/aws-sdk-go-v2/service/sso v1.30.7/go.mod h1:+fWt2UHSb4kS7Pu8y+BMBvJF0EWx+4H0hzNwtDNRTrg=
36+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 h1:AHDr0DaHIAo8c9t1emrzAlVDFp+iMMKnPdYy6XO4MCE=
37+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12/go.mod h1:GQ73XawFFiWxyWXMHWfhiomvP3tXtdNar/fi8z18sx0=
38+
github.com/aws/aws-sdk-go-v2/service/sts v1.41.5 h1:SciGFVNZ4mHdm7gpD1dgZYnCuVdX1s+lFTg4+4DOy70=
39+
github.com/aws/aws-sdk-go-v2/service/sts v1.41.5/go.mod h1:iW40X4QBmUxdP+fZNOpfmkdMZqsovezbAeO+Ubiv2pk=
40+
github.com/aws/smithy-go v1.24.0 h1:LpilSUItNPFr1eY85RYgTIg5eIEPtvFbskaFcmmIUnk=
41+
github.com/aws/smithy-go v1.24.0/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
1042
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0 h1:SmbUK/GxpAspRjSQbB6ARvH+ArzlNzTtHydNyXUQ6zg=
1143
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0/go.mod h1:vuD/xvJT9Y+ZVZRv4HQ42cMyPFIYqpc7AbB4Gvt/DlY=
1244
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
@@ -61,10 +93,6 @@ github.com/hashicorp/go-retryablehttp v0.6.4 h1:BbgctKO892xEyOXnGiaAwIoSq1QZ/SS4
6193
github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
6294
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
6395
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
64-
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
65-
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
66-
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
67-
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
6896
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
6997
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
7098
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=

0 commit comments

Comments
 (0)