Skip to content

Commit 2df31d5

Browse files
committed
Detect missing region, add option to specify region.
1 parent 0e7e21a commit 2df31d5

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tools/storage-advisor/src/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Config struct {
2626

2727
var mode = flag.String("mode", "cli", "Use as a CLI tool")
2828

29+
var region = flag.String("region", "", "AWS region")
30+
2931
var apiToken = flag.String("api-token", "", "API token for Joom Cloud")
3032

3133
var apiEndpoint = flag.String("api-endpoint", "https://api.cloud.joom.ai/v1", "API endpoint URL")
@@ -38,6 +40,9 @@ func main() {
3840
fmt.Printf("Error: could not initialize AWS config: %v\n", err)
3941
return
4042
}
43+
if region != nil {
44+
cfg.Region = *region
45+
}
4146
client := s3.NewFromConfig(cfg)
4247
api := NewApi(*apiEndpoint, apiToken)
4348

@@ -60,6 +65,16 @@ func main() {
6065
}
6166
log.Logger = zerolog.New(output).Level(zerolog.InfoLevel)
6267

68+
if cfg.Region == "" {
69+
fmt.Printf("Error: AWS region is not set.\n\n" +
70+
"Please either configured default region with\n" +
71+
" aws configure\n" +
72+
"or specify the region as option, e.g.\n" +
73+
" storage-advisor -region eu-central-1\n" +
74+
"(adjusting to your actual region)\n")
75+
return
76+
}
77+
6378
stsOutput, err := sts.NewFromConfig(cfg).GetCallerIdentity(rootCtx, &sts.GetCallerIdentityInput{})
6479
if err != nil {
6580
fmt.Printf("Error: unable to get your AWS indentity: %v\n\n"+

0 commit comments

Comments
 (0)