Skip to content

Commit 6242d3b

Browse files
committed
fix(aws): Fix AWS services initialization
1 parent df3b87c commit 6242d3b

File tree

2 files changed

+22
-54
lines changed

2 files changed

+22
-54
lines changed

pkg/aws/aws.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
1212
"github.com/aws/aws-sdk-go-v2/service/s3"
1313
"github.com/aws/aws-sdk-go-v2/service/sagemakerruntime"
14+
"github.com/aws/aws-sdk-go-v2/service/sfn"
15+
"github.com/aws/aws-sdk-go-v2/service/sqs"
1416
"github.com/aws/aws-sdk-go-v2/service/sts"
1517
)
1618

@@ -89,13 +91,13 @@ func (b *Builder) NewSagemakerRuntimeService(
8991

9092
func (b *Builder) NewSFNService(
9193
cfg aws.Config,
92-
serviceName string, opts ...func(options *sagemakerruntime.Options)) (*sagemakerruntime.Client, error) {
94+
serviceName string, opts ...func(options *sfn.Options)) (*sfn.Client, error) {
9395
sfnCfg, ok := b.config.SFN[serviceName]
9496
if !ok {
9597
return nil, fmt.Errorf("sfn config for service %s not found", serviceName)
9698
}
97-
defaultOpts := []func(*sagemakerruntime.Options){
98-
func(options *sagemakerruntime.Options) {
99+
defaultOpts := []func(*sfn.Options){
100+
func(options *sfn.Options) {
99101
if sfnCfg.Region != "" {
100102
options.Region = sfnCfg.Region
101103
}
@@ -110,17 +112,17 @@ func (b *Builder) NewSFNService(
110112

111113
opts = append(defaultOpts, opts...)
112114

113-
return sagemakerruntime.NewFromConfig(cfg, opts...), nil
115+
return sfn.NewFromConfig(cfg, opts...), nil
114116
}
115117

116118
func (b *Builder) NewSQSService(
117-
cfg aws.Config, serviceName string, opts ...func(options *s3.Options)) (*s3.Client, error) {
119+
cfg aws.Config, serviceName string, opts ...func(options *sqs.Options)) (*sqs.Client, error) {
118120
sqsCfg, ok := b.config.SQS[serviceName]
119121
if !ok {
120122
return nil, fmt.Errorf("sqs config for service %s not found", serviceName)
121123
}
122-
defaultOpts := []func(*s3.Options){
123-
func(options *s3.Options) {
124+
defaultOpts := []func(*sqs.Options){
125+
func(options *sqs.Options) {
124126
if sqsCfg.Region != "" {
125127
options.Region = sqsCfg.Region
126128
}
@@ -135,7 +137,7 @@ func (b *Builder) NewSQSService(
135137

136138
opts = append(defaultOpts, opts...)
137139

138-
return s3.NewFromConfig(cfg, opts...), nil
140+
return sqs.NewFromConfig(cfg, opts...), nil
139141
}
140142

141143
func createHttpClient(cfg *HTTPClient) *http.Client {

pkg/aws/aws_test.go

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -207,47 +207,30 @@ func TestBuilder(t *testing.T) {
207207
name: "Sfn service with HTTP client settings",
208208
fn: func(t *testing.T) {
209209
sfnSvc, err := builder.NewSFNService(c, "default")
210+
211+
// SFN service does not have access to options for now
210212
assert.NoError(t, err)
211213
assert.NotNil(t, sfnSvc)
212-
213-
opts := sfnSvc.Options()
214-
assert.Equal(t, opts.Region, "us-east-2")
215-
assert.NotNil(t, opts.HTTPClient)
216-
217-
httpTransport := opts.HTTPClient.(*http.Client).Transport.(*http.Transport)
218-
assert.Equal(t, httpTransport.MaxIdleConnsPerHost, 100)
219214
},
220215
},
221216
{
222217
name: "Sfn service with static credentials",
223218
fn: func(t *testing.T) {
224219
sfnSvc, err := builder.NewSFNService(c, "test")
220+
221+
// SFN service does not have access to options for now
225222
assert.NoError(t, err)
226223
assert.NotNil(t, sfnSvc)
227-
228-
opts := sfnSvc.Options()
229-
assert.Equal(t, opts.Region, "us-east-1")
230-
assert.NotNil(t, opts.Credentials)
231-
232-
creds := opts.Credentials.(credentials.StaticCredentialsProvider)
233-
assert.Equal(t, creds.Value.AccessKeyID, "test")
234-
assert.Equal(t, creds.Value.SecretAccessKey, "test")
235-
assert.Equal(t, creds.Value.SessionToken, "test")
236224
},
237225
},
238226
{
239227
name: "Sfn service with assume role credentials",
240228
fn: func(t *testing.T) {
241229
sfnSvc, err := builder.NewSFNService(c, "test2")
230+
231+
// SFN service does not have access to options for now
242232
assert.NoError(t, err)
243233
assert.NotNil(t, sfnSvc)
244-
245-
opts := sfnSvc.Options()
246-
assert.Equal(t, opts.Region, "us-west-2")
247-
assert.NotNil(t, opts.Credentials)
248-
249-
creds := opts.Credentials.(*aws.CredentialsCache)
250-
assert.NotNil(t, creds)
251234
},
252235
},
253236
{
@@ -262,47 +245,30 @@ func TestBuilder(t *testing.T) {
262245
name: "Sqs service with HTTP client settings",
263246
fn: func(t *testing.T) {
264247
sqsSvc, err := builder.NewSQSService(c, "default")
248+
249+
// SQS service does not have access to options for now
265250
assert.NoError(t, err)
266251
assert.NotNil(t, sqsSvc)
267-
268-
opts := sqsSvc.Options()
269-
assert.Equal(t, opts.Region, "us-east-2")
270-
assert.NotNil(t, opts.HTTPClient)
271-
272-
httpTransport := opts.HTTPClient.(*http.Client).Transport.(*http.Transport)
273-
assert.Equal(t, httpTransport.MaxIdleConnsPerHost, 100)
274252
},
275253
},
276254
{
277255
name: "Sqs service with static credentials",
278256
fn: func(t *testing.T) {
279257
sqsSvc, err := builder.NewSQSService(c, "test")
258+
259+
// SQS service does not have access to options for now
280260
assert.NoError(t, err)
281261
assert.NotNil(t, sqsSvc)
282-
283-
opts := sqsSvc.Options()
284-
assert.Equal(t, opts.Region, "us-east-1")
285-
assert.NotNil(t, opts.Credentials)
286-
287-
creds := opts.Credentials.(credentials.StaticCredentialsProvider)
288-
assert.Equal(t, creds.Value.AccessKeyID, "test")
289-
assert.Equal(t, creds.Value.SecretAccessKey, "test")
290-
assert.Equal(t, creds.Value.SessionToken, "test")
291262
},
292263
},
293264
{
294265
name: "Sqs service with assume role credentials",
295266
fn: func(t *testing.T) {
296267
sqsSvc, err := builder.NewSQSService(c, "test2")
268+
269+
// SQS service does not have access to options for now
297270
assert.NoError(t, err)
298271
assert.NotNil(t, sqsSvc)
299-
300-
opts := sqsSvc.Options()
301-
assert.Equal(t, opts.Region, "us-west-2")
302-
assert.NotNil(t, opts.Credentials)
303-
304-
creds := opts.Credentials.(*aws.CredentialsCache)
305-
assert.NotNil(t, creds)
306272
},
307273
},
308274
{

0 commit comments

Comments
 (0)