Skip to content

Commit 4e7353d

Browse files
committed
Add upfront AWS credential validation
1 parent eec0fce commit 4e7353d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/eks/eks.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ import (
1212
"github.com/guessi/eks-managed-node-groups/pkg/constants"
1313
)
1414

15+
func ValidateCredentials(region string) error {
16+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
17+
defer cancel()
18+
19+
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region))
20+
if err != nil {
21+
return fmt.Errorf("unable to load AWS config: %w", err)
22+
}
23+
24+
return nil
25+
}
26+
1527
func GetEksClient(region string) (*eks.Client, error) {
1628
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
1729
defer cancel()

pkg/ui/ui.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ func managedNodeGroupWorkflow(eksClient *eks.Client, clusterName string) error {
262262
}
263263

264264
func Entry(region string) error {
265+
if err := ekswrapper.ValidateCredentials(region); err != nil {
266+
return fmt.Errorf("credential validation failed: %w", err)
267+
}
268+
265269
eksClient, err := ekswrapper.GetEksClient(region)
266270
if err != nil {
267271
return err

0 commit comments

Comments
 (0)