From c2d339972644a9066466e770887e59c6fe8b974b Mon Sep 17 00:00:00 2001 From: Bill Havanki Date: Tue, 13 Aug 2024 13:36:33 -0400 Subject: [PATCH] fix: Find region correctly from EC2 IMDS (#549) When running on an EC2 instance with an instance profile / role, chamber now finds the region correctly. --- store/shared.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/store/shared.go b/store/shared.go index 937c301..5a1b50a 100644 --- a/store/shared.go +++ b/store/shared.go @@ -31,10 +31,11 @@ func getConfig(ctx context.Context, numRetries int, retryMode aws.RetryMode) (aw // If region is still not set, attempt to determine it via ec2 metadata API if cfg.Region == "" { imdsConfig, err := config.LoadDefaultConfig(ctx) - if err != nil { + if err == nil { ec2metadataSvc := imds.NewFromConfig(imdsConfig) if regionOverride, err := ec2metadataSvc.GetRegion(ctx, &imds.GetRegionInput{}); err == nil { region = regionOverride.Region + cfg.Region = region } } }