Skip to content

Commit e8d9977

Browse files
committed
Handle AWS Client session error in main
1 parent 55f3dba commit e8d9977

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cmd/sync/main.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ func main() {
5858
os.Exit(10)
5959
}
6060

61-
awsClient := createAWSClient(cfg.Region)
61+
awsClient, err := createAWSClient(cfg.Region)
62+
if err != nil {
63+
log.Printf("Couldn't create AWS client: %v", err)
64+
os.Exit(10)
65+
}
6266

6367
for _, ups := range cfg.Upstreams {
6468
if ups.Kind == "http" {
@@ -142,16 +146,16 @@ func main() {
142146
}
143147
}
144148

145-
func createAWSClient(region string) *AWSClient {
149+
func createAWSClient(region string) (*AWSClient, error) {
146150
httpClient := &http.Client{Timeout: connTimeoutInSecs * time.Second}
147151
cfg := &aws.Config{Region: aws.String(region), HTTPClient: httpClient}
148-
session, err := session.NewSession(cfg)
149152

153+
session, err := session.NewSession(cfg)
150154
if err != nil {
151-
log.Printf("Error while creating AWS Client: %v", err)
155+
return nil, err
152156
}
153157

154158
svcAutoscaling := autoscaling.New(session)
155159
svcEC2 := ec2.New(session)
156-
return NewAWSClient(svcEC2, svcAutoscaling)
160+
return NewAWSClient(svcEC2, svcAutoscaling), nil
157161
}

0 commit comments

Comments
 (0)