Skip to content

Conversation

prestist
Copy link
Contributor

@prestist prestist commented Sep 9, 2025

Migrate AWS SDK from v1 to v2
No functional changes intended beyond SDK upgrade.

Changes

  • (api.go): replace v1 session with config.LoadDefaultConfig and v2 clients.
  • Context: add context.Context to all AWS calls (currently context.TODO() placeholders).
  • Error handling: switch from awserr.Error to smithy.APIError with errors.As().
  • Types/enums:
    • v1 → v2 service types (e.g., ec2types.*, s3types.*).
    • Enums updated (e.g., ArchitectureTypeX8664, PermissionGroupAll, ImageAttributeNameLaunchPermission, SnapshotAttributeNameCreateVolumePermission).
    • Slices updated from []*T to []T/[]string as required.
    • Integers updated to int32 per v2 models (VolumeSize, SG ports).
  • S3: use s3types.ObjectCannedACL; v2 uploader/ops with contexts.
  • EC2 waiters: v1 waiter replaced with v2 ec2.NewImageAvailableWaiter(...).Wait(...).

TODO:

  • Replace context.TODO() with context.Background() or plumb ctx context.Context through public APIs for cancellation/timeouts.
  • ✅ Release/re-vender ignition because its pulling in AWS SDK v1 dependent on New release for ignition 2.23.0 ignition#2126

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully migrates the AWS Go SDK from v1 to v2. The changes are comprehensive, updating dependencies, client initialization, API call signatures, error handling, and various data types to align with the v2 SDK's patterns. The use of context.TODO() is noted as a temporary measure. My review focuses on ensuring the migration is correct and safe. I've identified a couple of critical issues where slice access could lead to a panic if an AWS resource is not found, and I've also provided a suggestion regarding context handling best practices.

input.AllRegions = aws.Bool(true)
}
output, err := a.ec2.DescribeRegions(&input)
output, err := a.ec2.DescribeRegions(context.TODO(), &input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the PR description acknowledges the use of context.TODO() as a placeholder, it's better practice to use context.Background() for operations that are not part of a specific request's lifecycle. This signals that the operation is intentionally not tied to a request context and is not a forgotten TODO. The long-term solution would be to plumb a context.Context through the public API methods to allow for cancellation and timeouts.

Suggested change
output, err := a.ec2.DescribeRegions(context.TODO(), &input)
output, err := a.ec2.DescribeRegions(context.Background(), &input)

@jbtrystram
Copy link
Member

Thank you so much for looking into this

@prestist
Copy link
Contributor Author

prestist commented Sep 10, 2025

Thank you so much for looking into this

No problem! a few steps left but hopefully soon.

@prestist prestist force-pushed the update-aws branch 3 times, most recently from ae76319 to a023fc8 Compare September 12, 2025 20:56
@prestist
Copy link
Contributor Author

Ok, CI should pass and this should be RTG.

Outstanding question we okay with just "context.background()" for all the Todo's or is that something that should be eval'd at a case by case basis and prob a followup pr?

@dustymabe
Copy link
Member

Thank you for working on this @prestist.

@marmijo could I lean on you for code review here in my stead?

Copy link
Member

@marmijo marmijo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, thank you for working on this! I'm working on testing this by building AWS images using this PR, but the migration looks clean.

Outstanding question we okay with just "context.background()" for all the Todo's or is that something that should be eval'd at a case by case basis and prob a followup pr?

I think it’s fine to switch them all to context.Background() in this PR. That’s what we do in the Azure API code already, so it keeps things consistent across providers. We're not using proper contexts over there either, so If we ever decide to plumb it up with cancellation/timeouts as a whole, that can be its own follow-up PR, but for now using Background() everywhere feels like the right move.

@marmijo
Copy link
Member

marmijo commented Sep 24, 2025

I rebased this PR locally onto the current main and ran a round of tests today. I was able to successfully build RHCOS, FCOS, and the WinLI AMIs with no issues. I also ran kola tests in AWS using the FCOS AMI, and all tests passed successfully. 🎉

@prestist
Copy link
Contributor Author

Updated @marmijo should be gtg once ci passes; thank you for the review!

- Update all imports from aws-sdk-go to aws-sdk-go-v2
- Migrate error handling from awserr.Error to smithy.APIError
- Update service client initialization (removed session, added direct clients)
- Add context parameters to API calls
- Update type references from ec2.Type to ec2types.Type
- Add AWS SDK v2 dependencies to go.mod
- Update slice handling from []*Type to []Type patterns
- Update integer type conversions (int64 to int32)
- Update architecture and volume type enums for v2
fixes:
S1008: should use 'return a.Version == b.Version' instead of 'if a.Version != b.Version { return false }; return true' (gosimple)
Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial LGTM - Proxy for @marmijo's previous code review.

@dustymabe dustymabe merged commit b3efd5b into coreos:main Sep 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants