or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced-configuration.mdconfiguration-loading.mdenvironment-configuration.mdindex.mdload-options.mdregion-configuration.mdshared-config-advanced.mdshared-config.md
tile.json

load-options.mddocs/

Load Options and Functional Options

Load options provide fine-grained control over AWS SDK configuration loading behavior through functional options pattern.

Overview

The LoadOptions struct contains all configurable options for LoadDefaultConfig. Functional options (functions prefixed with With) provide a convenient way to set these options.

LoadOptions Type

type LoadOptions struct {
    Region                           string
    Credentials                      aws.CredentialsProvider
    BearerAuthTokenProvider          smithybearer.TokenProvider
    HTTPClient                       HTTPClient
    EndpointResolver                 aws.EndpointResolver
    EndpointResolverWithOptions      aws.EndpointResolverWithOptions
    RetryMaxAttempts                 int
    RetryMode                        aws.RetryMode
    Retryer                          func() aws.Retryer
    APIOptions                       []func(*middleware.Stack) error
    Logger                           logging.Logger
    ClientLogMode                    *aws.ClientLogMode
    SharedConfigProfile              string
    SharedConfigFiles                []string
    SharedCredentialsFiles           []string
    CustomCABundle                   io.Reader
    DefaultRegion                    string
    UseEC2IMDSRegion                 *UseEC2IMDSRegion
    CredentialsCacheOptions          func(*aws.CredentialsCacheOptions)
    BearerAuthTokenCacheOptions      func(*smithybearer.TokenCacheOptions)
    SSOTokenProviderOptions          func(*ssocreds.SSOTokenProviderOptions)
    ProcessCredentialOptions         func(*processcreds.Options)
    EC2RoleCredentialOptions         func(*ec2rolecreds.Options)
    EndpointCredentialOptions        func(*endpointcreds.Options)
    WebIdentityRoleCredentialOptions func(*stscreds.WebIdentityRoleOptions)
    AssumeRoleCredentialOptions      func(*stscreds.AssumeRoleOptions)
    SSOProviderOptions               func(*ssocreds.Options)
    LogConfigurationWarnings         *bool
    S3UseARNRegion                   *bool
    S3DisableMultiRegionAccessPoints *bool
    EnableEndpointDiscovery          aws.EndpointDiscoveryEnableState
    EC2IMDSClientEnableState         imds.ClientEnableState
    EC2IMDSEndpointMode              imds.EndpointModeState
    EC2IMDSEndpoint                  string
    UseDualStackEndpoint             aws.DualStackEndpointState
    UseFIPSEndpoint                  aws.FIPSEndpointState
    DefaultsModeOptions              DefaultsModeOptions
    AppID                            string
    DisableRequestCompression        *bool
    RequestMinCompressSizeBytes      *int64
    S3DisableExpressAuth             *bool
    AccountIDEndpointMode            aws.AccountIDEndpointMode
}

type LoadOptionsFunc func(*LoadOptions) error

Region Configuration Options

func WithRegion(v string) LoadOptionsFunc

func WithDefaultRegion(v string) LoadOptionsFunc

func WithEC2IMDSRegion(fnOpts ...func(o *UseEC2IMDSRegion)) LoadOptionsFunc

WithRegion sets the AWS region for requests. This takes precedence over all other region sources.

WithDefaultRegion sets a fallback region used if a region is not resolved from other sources.

WithEC2IMDSRegion enables resolving the region from EC2 Instance Metadata Service.

Examples

// Explicit region
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithRegion("us-west-2"),
)

// Fallback region
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithDefaultRegion("us-east-1"),
)

// EC2 IMDS region
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithEC2IMDSRegion(),
)

Credentials Configuration Options

func WithCredentialsProvider(v aws.CredentialsProvider) LoadOptionsFunc

func WithCredentialsCacheOptions(v func(*aws.CredentialsCacheOptions)) LoadOptionsFunc

func WithProcessCredentialOptions(v func(*processcreds.Options)) LoadOptionsFunc

func WithEC2RoleCredentialOptions(v func(*ec2rolecreds.Options)) LoadOptionsFunc

func WithEndpointCredentialOptions(v func(*endpointcreds.Options)) LoadOptionsFunc

func WithWebIdentityRoleCredentialOptions(v func(*stscreds.WebIdentityRoleOptions)) LoadOptionsFunc

func WithAssumeRoleCredentialOptions(v func(*stscreds.AssumeRoleOptions)) LoadOptionsFunc

func WithSSOProviderOptions(v func(*ssocreds.Options)) LoadOptionsFunc

func WithSSOTokenProviderOptions(v func(*ssocreds.SSOTokenProviderOptions)) LoadOptionsFunc

func WithBearerAuthTokenProvider(v smithybearer.TokenProvider) LoadOptionsFunc

func WithBearerAuthTokenCacheOptions(v func(*smithybearer.TokenCacheOptions)) LoadOptionsFunc

Examples

import (
    "github.com/aws/aws-sdk-go-v2/credentials"
)

// Static credentials
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithCredentialsProvider(
        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
    ),
)

// Configure credentials cache
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithCredentialsCacheOptions(func(options *aws.CredentialsCacheOptions) {
        options.ExpiryWindow = 30 * time.Second
    }),
)

// Configure assume role options
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithAssumeRoleCredentialOptions(func(options *stscreds.AssumeRoleOptions) {
        options.Duration = 3600 * time.Second
    }),
)

Shared Configuration Options

func WithSharedConfigProfile(v string) LoadOptionsFunc

func WithSharedConfigFiles(v []string) LoadOptionsFunc

func WithSharedCredentialsFiles(v []string) LoadOptionsFunc

Examples

// Use specific profile
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithSharedConfigProfile("production"),
)

// Custom config file
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithSharedConfigFiles([]string{"/path/to/custom/config"}),
)

// Custom credentials file
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithSharedCredentialsFiles([]string{"/path/to/custom/credentials"}),
)

HTTP Client Options

func WithHTTPClient(v HTTPClient) LoadOptionsFunc

func WithCustomCABundle(v io.Reader) LoadOptionsFunc

Examples

import (
    "net/http"
    "time"
    "os"
)

// Custom HTTP client
customClient := &http.Client{
    Timeout: 30 * time.Second,
}

cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithHTTPClient(customClient),
)

// Custom CA bundle
caBundle, _ := os.Open("/path/to/ca-bundle.pem")
defer caBundle.Close()

cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithCustomCABundle(caBundle),
)

Retry Configuration Options

func WithRetryMaxAttempts(v int) LoadOptionsFunc

func WithRetryMode(v aws.RetryMode) LoadOptionsFunc

func WithRetryer(v func() aws.Retryer) LoadOptionsFunc

Examples

// Set max retry attempts
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithRetryMaxAttempts(5),
)

// Set retry mode
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithRetryMode(aws.RetryModeAdaptive),
)

Logging Configuration Options

func WithLogger(v logging.Logger) LoadOptionsFunc

func WithClientLogMode(v aws.ClientLogMode) LoadOptionsFunc

func WithLogConfigurationWarnings(v bool) LoadOptionsFunc

Examples

import (
    "os"
    "github.com/aws/smithy-go/logging"
)

// Configure logger
logger := logging.NewStandardLogger(os.Stdout)

cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithLogger(logger),
    config.WithClientLogMode(aws.LogRetries | aws.LogRequest | aws.LogResponse),
)

// Enable configuration warnings
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithLogConfigurationWarnings(true),
)

Endpoint Configuration Options

func WithEndpointResolver(v aws.EndpointResolver) LoadOptionsFunc

func WithEndpointResolverWithOptions(v aws.EndpointResolverWithOptions) LoadOptionsFunc

func WithUseDualStackEndpoint(v aws.DualStackEndpointState) LoadOptionsFunc

func WithUseFIPSEndpoint(v aws.FIPSEndpointState) LoadOptionsFunc

func WithEndpointDiscovery(v aws.EndpointDiscoveryEnableState) LoadOptionsFunc

Note: WithEndpointResolver and WithEndpointResolverWithOptions are deprecated. Use service-specific endpoint resolution instead.

Examples

// Enable dual-stack endpoints
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithUseDualStackEndpoint(aws.DualStackEndpointStateEnabled),
)

// Enable FIPS endpoints
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithUseFIPSEndpoint(aws.FIPSEndpointStateEnabled),
)

// Enable endpoint discovery
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithEndpointDiscovery(aws.EndpointDiscoveryEnabled),
)

EC2 IMDS Configuration Options

func WithEC2IMDSClientEnableState(v imds.ClientEnableState) LoadOptionsFunc

func WithEC2IMDSEndpointMode(v imds.EndpointModeState) LoadOptionsFunc

func WithEC2IMDSEndpoint(v string) LoadOptionsFunc

Examples

import (
    "github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
)

// Enable EC2 IMDS client
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithEC2IMDSClientEnableState(imds.ClientEnabled),
)

// Set IMDS endpoint mode to IPv6
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithEC2IMDSEndpointMode(imds.EndpointModeStateIPv6),
)

// Custom IMDS endpoint
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithEC2IMDSEndpoint("http://169.254.169.254"),
)

S3-Specific Configuration Options

func WithS3UseARNRegion(v bool) LoadOptionsFunc

func WithS3DisableMultiRegionAccessPoints(v bool) LoadOptionsFunc

func WithS3DisableExpressAuth(v bool) LoadOptionsFunc

Examples

// Allow S3 ARNs to direct region
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithS3UseARNRegion(true),
)

// Disable S3 multi-region access points
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithS3DisableMultiRegionAccessPoints(true),
)

// Disable S3 Express auth
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithS3DisableExpressAuth(true),
)

SDK Defaults Configuration Options

func WithDefaultsMode(mode aws.DefaultsMode, optFns ...func(options *DefaultsModeOptions)) LoadOptionsFunc

Examples

// Set defaults mode to standard
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithDefaultsMode(aws.DefaultsModeStandard),
)

// Set defaults mode to auto with custom IMDS client
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithDefaultsMode(aws.DefaultsModeAuto, func(options *config.DefaultsModeOptions) {
        options.IMDSClient = imds.New(imds.Options{})
    }),
)

Request Compression Options

func WithDisableRequestCompression(DisableRequestCompression *bool) LoadOptionsFunc

func WithRequestMinCompressSizeBytes(RequestMinCompressSizeBytes *int64) LoadOptionsFunc

Examples

// Disable request compression
disableCompression := true
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithDisableRequestCompression(&disableCompression),
)

// Set minimum compression size
minSize := int64(10240) // 10KB
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithRequestMinCompressSizeBytes(&minSize),
)

Advanced Configuration Options

func WithAPIOptions(v []func(*middleware.Stack) error) LoadOptionsFunc

func WithAppID(ID string) LoadOptionsFunc

func WithAccountIDEndpointMode(m aws.AccountIDEndpointMode) LoadOptionsFunc

Examples

import (
    "github.com/aws/smithy-go/middleware"
)

// Add API middleware
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithAPIOptions([]func(*middleware.Stack) error{
        func(stack *middleware.Stack) error {
            // Add custom middleware
            return nil
        },
    }),
)

// Set SDK app ID
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithAppID("my-application-id"),
)

// Set account ID endpoint mode
cfg, err := config.LoadDefaultConfig(
    context.TODO(),
    config.WithAccountIDEndpointMode(aws.AccountIDEndpointModeRequired),
)

LoadOptions Methods

func (o LoadOptions) GetRetryMaxAttempts(ctx context.Context) (int, bool, error)

func (o LoadOptions) GetRetryMode(ctx context.Context) (aws.RetryMode, bool, error)

func (o LoadOptions) GetS3DisableExpressAuth() (value, ok bool)

func (o LoadOptions) GetS3DisableMultiRegionAccessPoints(ctx context.Context) (v bool, found bool, err error)

func (o LoadOptions) GetS3UseARNRegion(ctx context.Context) (v bool, found bool, err error)

func (o LoadOptions) GetUseDualStackEndpoint(ctx context.Context) (value aws.DualStackEndpointState, found bool, err error)

func (o LoadOptions) GetUseFIPSEndpoint(ctx context.Context) (value aws.FIPSEndpointState, found bool, err error)

func (o LoadOptions) GetEnableEndpointDiscovery(ctx context.Context) (value aws.EndpointDiscoveryEnableState, ok bool, err error)

func (o LoadOptions) GetEC2IMDSClientEnableState() (imds.ClientEnableState, bool, error)

func (o LoadOptions) GetEC2IMDSEndpointMode() (imds.EndpointModeState, bool, error)

func (o LoadOptions) GetEC2IMDSEndpoint() (string, bool, error)