Repository navigation
refactor(aws): collapse per-region client boilerplate into helpers (#297) - #359
Merged
Merged
Conversation
) The pkg/aws hot path repeated cfg := c.cfg.Copy(); cfg.Region = region; ec2.NewFromConfig(cfg) ~40 times across 16 files. Add two helpers on Client — regionalEC2(region) *ec2.Client and regionalConfig(region) aws.Config — and route every site through them. Sites that build a non-EC2 client (fsx/s3/ssm/ imagebuilder) or reuse the config use regionalConfig; the rest use regionalEC2. Retire getRegionalConfig(ctx, region) (aws.Config, error): its returned error was always nil, so its callers carried dead 'if err != nil' branches — those are removed too. regionalConfig treats an empty region as a no-op (default-chain region preserved), matching the prior conditional 'if region != ""' sites, so behavior is byte-identical. Net -166 lines. Closes #297.
scttfrdmn
force-pushed
the
refactor/297-regional-ec2
branch
from
July 15, 2026 20:44
2a6354b to
c594b75
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Collapses the ~40 repeated per-region client-construction sites in
pkg/awsbehind two helpers, and retires the always-nil-errorgetRegionalConfig.Helpers (new
pkg/aws/regional.go)What changed
cfg := c.cfg.Copy(); cfg.Region = region; ec2.NewFromConfig(cfg)sites across 16 files →c.regionalEC2(region)(EC2 sites) orc.regionalConfig(region)(fsx/s3/ssm/imagebuilder sites, and sites that reuse the config).getRegionalConfig(ctx, region) (aws.Config, error)— its error was always nil, so its Pattern-D callers (ami_base/ami_checks/ami_mgmt/snapshot_build) also shed deadif err != nilbranches.Safety
regionalConfigtreats empty region as a no-op (default-chain region preserved), matching the priorif region != ""conditional sites (cleanupGetInstanceElasticIP, imagebuilderWaitForImage) — byte-identical behavior.go build ./...clean,gofmt/go vetclean,go test ./pkg/awsgreen (incl.TestBuildInlinePolicy).Closes #297.