tessl install tessl/go-github-com-aws-aws-sdk-go-v2--config@1.32.0Utilities for loading AWS SDK configuration from multiple sources including environment variables and shared configuration files
The config package provides utilities for loading and managing AWS SDK configuration from multiple sources including environment variables, AWS shared configuration files (/.aws/config), and AWS shared credentials files (/.aws/credentials). It offers the primary LoadDefaultConfig function that loads configuration from all supported SDK sources and resolves credentials using the SDK's default credential chain.
go get github.com/aws/aws-sdk-go-v2/config@v1.32.2import (
"context"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/aws"
)package main
import (
"context"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/config"
)
func main() {
// Load default configuration
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
}
// Configuration is now ready to use with AWS service clients
fmt.Printf("Region: %s\n", cfg.Region)
}Load AWS SDK configuration from environment variables and shared config files with customizable options.
func LoadDefaultConfig(ctx context.Context, optFns ...func(*LoadOptions) error) (cfg aws.Config, err error)Retrieve AWS configuration from environment variables.
type EnvConfig struct {
Credentials aws.Credentials
ContainerCredentialsEndpoint string
ContainerCredentialsRelativePath string
ContainerAuthorizationToken string
Region string
SharedConfigProfile string
SharedCredentialsFile string
SharedConfigFile string
CustomCABundle string
EnableEndpointDiscovery aws.EndpointDiscoveryEnableState
WebIdentityTokenFilePath string
RoleARN string
RoleSessionName string
S3UseARNRegion *bool
EC2IMDSClientEnableState imds.ClientEnableState
EC2IMDSv1Disabled *bool
EC2IMDSEndpointMode imds.EndpointModeState
EC2IMDSEndpoint string
S3DisableMultiRegionAccessPoints *bool
UseDualStackEndpoint aws.DualStackEndpointState
UseFIPSEndpoint aws.FIPSEndpointState
DefaultsMode aws.DefaultsMode
RetryMaxAttempts int
RetryMode aws.RetryMode
AppID string
IgnoreConfiguredEndpoints *bool
BaseEndpoint string
DisableRequestCompression *bool
RequestMinCompressSizeBytes *int64
S3DisableExpressAuth *bool
AccountIDEndpointMode aws.AccountIDEndpointMode
}
func NewEnvConfig() (EnvConfig, error)Configure the behavior of LoadDefaultConfig using functional options.
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) errorLoad Options and Functional Options
Access default file paths and manage AWS shared configuration and credentials files.
func DefaultSharedConfigFilename() string
func DefaultSharedCredentialsFilename() string
var DefaultSharedConfigFiles []string
var DefaultSharedCredentialsFiles []string
const DefaultSharedConfigProfile = "default"Direct access to shared configuration file structures for advanced scenarios.
func LoadSharedConfigProfile(ctx context.Context, profile string, optFns ...func(*LoadSharedConfigOptions)) (SharedConfig, error)
type SharedConfig struct {
Profile string
Region string
Credentials aws.Credentials
RoleARN string
SSOSessionName string
// And 30+ additional fields
}
type LoadSharedConfigOptions struct {
CredentialsFiles []string
ConfigFiles []string
Logger logging.Logger
}
type SSOSession struct {
Name string
SSORegion string
SSOStartURL string
}
type Services struct {
ServiceValues map[string]map[string]string
}Configure region resolution from EC2 Instance Metadata Service.
type UseEC2IMDSRegion struct {
Client *imds.Client
}Configure SDK defaults mode and other advanced options.
type DefaultsModeOptions struct {
Mode aws.DefaultsMode
IMDSClient *imds.Client
}
type HTTPClient interface {
Do(*http.Request) (*http.Response, error)
}type AssumeRoleTokenProviderNotSetError struct{}
func (e AssumeRoleTokenProviderNotSetError) Error() string
type CredentialRequiresARNError struct {
Type string
Profile string
}
func (e CredentialRequiresARNError) Error() string
type SharedConfigLoadError struct{}
func (e SharedConfigLoadError) Error() string
func (e SharedConfigLoadError) Unwrap() error
type SharedConfigAssumeRoleError struct{}
func (e SharedConfigAssumeRoleError) Error() string
func (e SharedConfigAssumeRoleError) Unwrap() error
type SharedConfigProfileNotExistError struct{}
func (e SharedConfigProfileNotExistError) Error() string
func (e SharedConfigProfileNotExistError) Unwrap() errorconst (
DefaultSharedConfigProfile = "default"
)
const CredentialsSourceName = "EnvConfigCredentials"var DefaultSharedConfigFiles = []string{
DefaultSharedConfigFilename(),
}
var DefaultSharedCredentialsFiles = []string{
DefaultSharedCredentialsFilename(),
}