awsopt

awsopt builds an aws-sdk-go-v2 configuration once as a composable option slice, so every AWS client in a service shares identical settings.

Part of nurago, a collection of independent Go packages for backend services.

import "github.com/tecnickcom/nurago/pkg/awsopt"

Accumulates aws-sdk-go-v2 load options into a reusable slice, then materialises them into an aws.Config.

var opts awsopt.Options

opts.WithRegion("eu-west-1")

cfg, err := opts.LoadDefaultConfig(ctx)

The zero value is ready to use.

One configuration, several clients

A service using S3, SQS and Secrets Manager constructs three SDK clients. Each needs region, credentials, endpoint resolution and retry behaviour, and the SDK’s own pattern is to pass load options at each construction site.

Repeated three times, those settings drift. One client ends up on a different endpoint after a test change, or misses a credential provider added later, and the failure appears as one AWS service behaving differently from the others.

Options is built once and handed to every AWS-based package in this module: s3, sqs and awssecretcache all accept it. Changing the region or injecting a test endpoint is one edit that reaches all of them.

Region from a URL

WithRegionFromURL extracts the region from a service endpoint rather than requiring it separately.

AWS endpoint URLs embed the region: an SQS queue URL contains it, and so does an S3 endpoint. Deriving it removes a class of configuration error where a queue URL is updated to a different region and the configured region is not, producing a signing mismatch rather than a clear failure.

sqs does this by default, deriving the region from the queue URL unless one is set explicitly.

Escape hatch

WithAWSOption appends any config.LoadOptionsFunc, so anything the SDK supports and this package does not name is still reachable: custom credential providers, retry configuration, HTTP client substitution, shared config profiles.

LoadDefaultConfig delegates to the SDK’s own config.LoadDefaultConfig, so the standard resolution chain applies unchanged. Environment variables, shared config files, instance metadata and container credentials all behave exactly as they would without this package, and the options accumulated here are layered on top.

Nothing here replaces the SDK’s behaviour. It composes it.

Dependencies

Reaches github.com/aws/aws-sdk-go-v2/config.