Skip to content

Commit e80c533

Browse files
committed
Bug fix: log client creation doesn't change region in session
1 parent bbcc865 commit e80c533

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

ecs-cli/modules/clients/aws/cloudwatchlogs/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cloudwatchlogs
1616
import (
1717
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients"
1818
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/config"
19+
"github.com/aws/aws-sdk-go/aws"
1920
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
2021
"github.com/aws/aws-sdk-go/service/cloudwatchlogs/cloudwatchlogsiface"
2122
)
@@ -33,9 +34,8 @@ type cwLogsClient struct {
3334

3435
// NewCloudWatchLogsClient creates an instance of ec2Client object.
3536
func NewCloudWatchLogsClient(params *config.CommandConfig, logRegion string) Client {
36-
session := params.Session
37-
session.Config = session.Config.WithRegion(logRegion)
38-
client := cloudwatchlogs.New(session)
37+
newSession := params.Session.Copy(&aws.Config{Region: aws.String(logRegion)})
38+
client := cloudwatchlogs.New(newSession)
3939
client.Handlers.Build.PushBackNamed(clients.CustomUserAgentHandler())
4040
return &cwLogsClient{
4141
client: client,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package cloudwatchlogs
15+
16+
import (
17+
"testing"
18+
19+
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/config"
20+
"github.com/aws/aws-sdk-go/aws"
21+
"github.com/aws/aws-sdk-go/aws/session"
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestNewCloudWatchLogsClientLeavesRegionIntact(t *testing.T) {
26+
// Test that it doesn't mess up command config session and re-set the region
27+
correctRegion := "eu-west-1"
28+
sess, err := session.NewSession(&aws.Config{
29+
Region: aws.String(correctRegion),
30+
})
31+
assert.NoError(t, err)
32+
params := &config.CommandConfig{
33+
Session: sess,
34+
}
35+
36+
NewCloudWatchLogsClient(params, "us-east-2")
37+
38+
assert.Equal(t, correctRegion, aws.StringValue(params.Session.Config.Region), "Expected configured region to remain unchanged after call to NewCloudWatchLogsClient()")
39+
40+
}

0 commit comments

Comments
 (0)