Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Update AWS endpoint resolution #252

Closed
TylerHendrickson opened this issue Aug 10, 2023 · 0 comments · Fixed by #542
Closed

[Bug]: Update AWS endpoint resolution #252

TylerHendrickson opened this issue Aug 10, 2023 · 0 comments · Fixed by #542
Labels
bug Something isn't working go Pull requests that update Go code good first issue Good for newcomers help wanted Extra attention is needed

Comments

@TylerHendrickson
Copy link
Member

TylerHendrickson commented Aug 10, 2023

Why is this issue important?

As of the 2023-07-31 release of the github.com/aws/aws-sdk-go-v2 library, use of the "v1" EndpointResolver and provided is deprecated. This is documented here in the AWS SDK for Go V2 Developer Guide.

We use the now-deprecated EndpointResolver in the internal/awsHelpers` package to configure SQS clients in a manner that is compatible with both real-world AWS usage and LocalStack.

Current State

The Staticcheck linter fails on two lines of the GetSQSClient function defined in internal/awsHelpers/config.go due to SA1019 - Using a deprecated function, variable, constant or field and provides the following output:

Error: internal/awsHelpers/config.go:44:10: cfg.EndpointResolverWithOptions is deprecated: with the release of endpoint resolution v2 in API clients, EndpointResolver and EndpointResolverWithOptions are deprecated. Providing a value for this field will likely prevent you from using newer endpoint-related service features. See API client options EndpointResolverV2 and BaseEndpoint. (SA1019)
Error: internal/awsHelpers/config.go:50:4: o.EndpointResolver is deprecated: Deprecated: EndpointResolver and WithEndpointResolver. Providing a value for this field will likely prevent you from using any endpoint-related service features released after the introduction of EndpointResolverV2 and BaseEndpoint. To migrate an EndpointResolver implementation that uses a custom endpoint, set the client option BaseEndpoint instead. (SA1019)

Expected State

  1. Endpoints are configured on SDK clients without relying on the deprecated EndpointResolver.
  2. Staticcheck execution can succeed without adding any lint:ignore comment directives.

Implementation Plan

  1. Suppress the Staticcheck linter issues that are currently causing PRs to fail by adding //lint:ignore SA1019 ... comment directives to the offending lines.
  2. Update the internal/awsHelpers package to use the newly-available EndpointResolverV2 and/or BaseEndpoint instead of EndpointResolver.
  3. Remove the //lint:ignore comment directives added in Step 1.

Relevant Code Snippets

func GetSQSClient(ctx context.Context) (*sqs.Client, error) {
	cfg, err := GetConfig(ctx)
	if err != nil {
		return nil, fmt.Errorf("could not create AWS SDK config: %w", err)
	}

	var sqsResolver sqs.EndpointResolverFunc = func(region string, options sqs.EndpointResolverOptions) (aws.Endpoint, error) {
		return cfg.EndpointResolverWithOptions.ResolveEndpoint("sqs", cfg.Region)
	}
	client := sqs.NewFromConfig(cfg, func(o *sqs.Options) {
		// the logic for providing the config above doesn't affect the endpoint for SQS, and this is
		// needed so that localstack will work
		if _, isSet := os.LookupEnv("LOCALSTACK_HOSTNAME"); isSet {
			o.EndpointResolver = sqsResolver
		}
	})

	return client, nil
}

Failing lines:

  • return cfg.EndpointResolverWithOptions.ResolveEndpoint("sqs", cfg.Region)
  • o.EndpointResolver = sqsResolver
@TylerHendrickson TylerHendrickson added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed go Pull requests that update Go code labels Aug 10, 2023
@TylerHendrickson TylerHendrickson changed the title [Issue]: Update AWS endpoint resolution [Bug]: Update AWS endpoint resolution Aug 10, 2023
@TylerHendrickson TylerHendrickson linked a pull request Dec 12, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working go Pull requests that update Go code good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant