config

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2020 License: Apache-2.0 Imports: 24 Imported by: 6,908

Documentation

Overview

Package config provides utilities for loading configuration from multiple sources that can be used to configure the SDK's API clients, and utilities.

The config package will load configuration from environment variables, AWS shared configuration file (~/.aws/config), and AWS shared credentials file (~/.aws/credentials).

Use the LoadDefaultConfig to load configuration from all the SDK's supported sources, and resolve credentials using the SDK's default credential chain.

LoadDefaultConfig allows for a variadic list of additional Config sources that can provide one or more configuration values which can be used to programmatically control the resolution of a specific value, or allow for broader range of additional configuration sources not supported by the SDK. A Config source implements one or more provider interfaces defined in this package. Config sources passed in will take precedence over the default environment and shared config sources used by the SDK. If one or more Config sources implement the same provider interface, priority will be handled by the order in which the sources were passed in.

A number of helpers (prefixed by “With“) are provided in this package that implement their respective provider interface. These helpers should be used for overriding configuration programatically at runtime.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/sts"
)

func main() {
	cfg, err := config.LoadDefaultConfig()
	if err != nil {
		log.Fatal(err)
	}

	client := sts.NewFromConfig(cfg)

	identity, err := client.GetCallerIdentity(context.Background(), &sts.GetCallerIdentityInput{})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Account: %s, Arn: %s", aws.ToString(identity.Account), aws.ToString(identity.Arn))
}
Output:

Example (Custom_config)
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/sts"
)

func main() {
	// Config sources can be passed to LoadDefaultConfig, these sources can implement one or more
	// provider interfaces. These sources take priority over the standard environment and shared configuration values.
	cfg, err := config.LoadDefaultConfig(
		config.WithRegion("us-west-2"),
		config.WithSharedConfigProfile("customProfile"),
	)
	if err != nil {
		log.Fatal(err)
	}

	client := sts.NewFromConfig(cfg)

	identity, err := client.GetCallerIdentity(context.Background(), &sts.GetCallerIdentityInput{})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Account: %s, Arn: %s", aws.ToString(identity.Account), aws.ToString(identity.Arn))
}
Output:

Index

Examples

Constants

View Source
const CredentialsSourceName = "EnvConfigCredentials"

CredentialsSourceName provides a name of the provider when config is loaded from environment.

View Source
const (

	// DefaultSharedConfigProfile is the default profile to be used when
	// loading configuration from the config files if another profile name
	// is not provided.
	DefaultSharedConfigProfile = `default`
)

Variables

DefaultSharedConfigFiles is a slice of the default shared config files that the will be used in order to load the SharedConfig.

Functions

func DefaultSharedConfigFilename

func DefaultSharedConfigFilename() string

DefaultSharedConfigFilename returns the SDK's default file path for the shared config file.

Builds the shared config file path based on the OS's platform.

  • Linux/Unix: $HOME/.aws/config
  • Windows: %USERPROFILE%\.aws\config

func DefaultSharedCredentialsFilename

func DefaultSharedCredentialsFilename() string

DefaultSharedCredentialsFilename returns the SDK's default file path for the shared credentials file.

Builds the shared config file path based on the OS's platform.

  • Linux/Unix: $HOME/.aws/credentials
  • Windows: %USERPROFILE%\.aws\credentials

func LoadDefaultConfig

func LoadDefaultConfig(cfgs ...Config) (aws.Config, error)

LoadDefaultConfig reads the SDK's default external configurations, and populates an AWS Config with the values from the external configurations.

An optional variadic set of additional Config values can be provided as input that will be prepended to the configs slice. Use this to add custom configuration. The custom configurations must satisfy the respective providers for their data or the custom data will be ignored by the resolvers and config loaders.

cfg, err := config.LoadDefaultConfig(
   WithSharedConfigProfile("test-profile"),
)
if err != nil {
   panic(fmt.Sprintf("failed loading config, %v", err))
}

The default configuration sources are: * Environment Variables * Shared Configuration and Shared Credentials files.

Types

type APIOptionsProvider

type APIOptionsProvider interface {
	GetAPIOptions() ([]func(*middleware.Stack) error, bool, error)
}

APIOptionsProvider is an interface for retrieving APIOptions.

type AssumeRoleCredentialOptionsProvider added in v0.2.0

type AssumeRoleCredentialOptionsProvider interface {
	GetAssumeRoleCredentialOptions() (func(*stscreds.AssumeRoleOptions), bool, error)
}

AssumeRoleCredentialOptionsProvider is an interface for retrieving a function for setting the stscreds.AssumeRoleOptions.

type AssumeRoleTokenProviderNotSetError

type AssumeRoleTokenProviderNotSetError struct{}

AssumeRoleTokenProviderNotSetError is an error returned when creating a session when the MFAToken option is not set when shared config is configured load assume a role with an MFA token.

func (AssumeRoleTokenProviderNotSetError) Error

Error is the error message

type Config

type Config interface{}

A Config represents a generic configuration value or set of values. This type will be used by the AWSConfigResolvers to extract

General the Config type will use type assertion against the Provider interfaces to extract specific data from the Config.

type CredentialRequiresARNError

type CredentialRequiresARNError struct {
	// type of credentials that were configured.
	Type string

	// Profile name the credentials were in.
	Profile string
}

CredentialRequiresARNError provides the error for shared config credentials that are incorrectly configured in the shared config or credentials file.

func (CredentialRequiresARNError) Error

Error satisfies the error interface.

type CredentialsProviderProvider

type CredentialsProviderProvider interface {
	GetCredentialsProvider() (aws.CredentialsProvider, bool, error)
}

CredentialsProviderProvider provides access to the credentials external configuration value.

func WithCredentialsProvider

func WithCredentialsProvider(provider aws.CredentialsProvider) CredentialsProviderProvider

WithCredentialsProvider provides wrapping of a credentials Value to satisfy the CredentialsProviderProvider interface.

Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	cfg, err := config.LoadDefaultConfig(
		// Hard coded credentials.
		config.WithCredentialsProvider(credentials.StaticCredentialsProvider{
			Value: aws.Credentials{
				AccessKeyID: "AKID", SecretAccessKey: "SECRET", SessionToken: "SESSION",
				Source: "example hard coded credentials",
			},
		}))
	if err != nil {
		log.Fatal(err)
	}

	// Credentials retrieve will be called automatically internally to the SDK
	// service clients created with the cfg value.
	creds, err := cfg.Credentials.Retrieve(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Credentials Source:", creds.Source)
	// Credentials Source: example hard coded credentials
}
Output:

type CustomCABundleProvider

type CustomCABundleProvider interface {
	GetCustomCABundle() ([]byte, error)
}

CustomCABundleProvider provides access to the custom CA bundle PEM bytes.

type DefaultRegionProvider

type DefaultRegionProvider interface {
	GetDefaultRegion() (string, bool, error)
}

DefaultRegionProvider is an interface for retrieving a default region if a region was not resolved from other sources

type EC2RoleCredentialOptionsProvider added in v0.2.0

type EC2RoleCredentialOptionsProvider interface {
	GetEC2RoleCredentialOptions() (func(*ec2rolecreds.Options), bool, error)
}

EC2RoleCredentialOptionsProvider is an interface for retrieving a function for setting the ec2rolecreds.Provider options.

type EndpointCredentialOptionsProvider added in v0.2.0

type EndpointCredentialOptionsProvider interface {
	GetEndpointCredentialOptions() (func(*endpointcreds.Options), bool, error)
}

EndpointCredentialOptionsProvider is an interface for retrieving a function for setting the endpointcreds.ProviderOptions.

type EndpointResolverProvider added in v0.2.0

type EndpointResolverProvider interface {
	GetEndpointResolver() (aws.EndpointResolver, bool, error)
}

EndpointResolverProvider is an interface for retrieving an aws.EndpointResolver from a configuration source

func WithEndpointResolver

func WithEndpointResolver(resolver aws.EndpointResolver) EndpointResolverProvider

WithEndpointResolver wraps a aws.EndpointResolver value to satisfy the EndpointResolverProvider interface

Example
package main

import (
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
)

func main() {
	cfg, err := config.LoadDefaultConfig(config.WithEndpointResolver(
		aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
			return aws.Endpoint{URL: "https://mock.amazonaws.com"}, nil
		})))
	if err != nil {
		log.Fatal(err)
	}
	_ = cfg
}
Output:

type EnvConfig

type EnvConfig struct {
	// Environment configuration values. If set both Access Key ID and Secret Access
	// Key must be provided. Session Token and optionally also be provided, but is
	// not required.
	//
	//	# Access Key ID
	//	AWS_ACCESS_KEY_ID=AKID
	//	AWS_ACCESS_KEY=AKID # only read if AWS_ACCESS_KEY_ID is not set.
	//
	//	# Secret Access Key
	//	AWS_SECRET_ACCESS_KEY=SECRET
	//	AWS_SECRET_KEY=SECRET # only read if AWS_SECRET_ACCESS_KEY is not set.
	//
	//	# Session Token
	//	AWS_SESSION_TOKEN=TOKEN
	Credentials aws.Credentials

	// ContainerCredentialsEndpoint value is the HTTP enabled endpoint to retrieve credentials
	// using the endpointcreds.Provider
	ContainerCredentialsEndpoint string

	// ContainerCredentialsRelativePath is the relative URI path that will be used when attempting to retrieve
	// credentials from the container endpoint.
	ContainerCredentialsRelativePath string

	// ContainerAuthorizationToken is the authorization token that will be included in the HTTP Authorization
	// header when attempting to retrieve credentials from the container credentials endpoint.
	ContainerAuthorizationToken string

	// Region value will instruct the SDK where to make service API requests to. If is
	// not provided in the environment the region must be provided before a service
	// client request is made.
	//
	//	AWS_REGION=us-west-2
	//	AWS_DEFAULT_REGION=us-west-2
	Region string

	// Profile name the SDK should load use when loading shared configuration from the
	// shared configuration files. If not provided "default" will be used as the
	// profile name.
	//
	//	AWS_PROFILE=my_profile
	//	AWS_DEFAULT_PROFILE=my_profile
	SharedConfigProfile string

	// Shared credentials file path can be set to instruct the SDK to use an alternate
	// file for the shared credentials. If not set the file will be loaded from
	// $HOME/.aws/credentials on Linux/Unix based systems, and
	// %USERPROFILE%\.aws\credentials on Windows.
	//
	//	AWS_SHARED_CREDENTIALS_FILE=$HOME/my_shared_credentials
	SharedCredentialsFile string

	// Shared config file path can be set to instruct the SDK to use an alternate
	// file for the shared config. If not set the file will be loaded from
	// $HOME/.aws/config on Linux/Unix based systems, and
	// %USERPROFILE%\.aws\config on Windows.
	//
	//	AWS_CONFIG_FILE=$HOME/my_shared_config
	SharedConfigFile string

	// Sets the path to a custom Credentials Authority (CA) Bundle PEM file
	// that the SDK will use instead of the system's root CA bundle.
	// Only use this if you want to configure the SDK to use a custom set
	// of CAs.
	//
	// Enabling this option will attempt to merge the Transport
	// into the SDK's HTTP client. If the client's Transport is
	// not a http.Transport an error will be returned. If the
	// Transport's TLS config is set this option will cause the
	// SDK to overwrite the Transport's TLS config's  RootCAs value.
	//
	// Setting a custom HTTPClient in the aws.Config options will override this setting.
	// To use this option and custom HTTP client, the HTTP client needs to be provided
	// when creating the config. Not the service client.
	//
	//  AWS_CA_BUNDLE=$HOME/my_custom_ca_bundle
	CustomCABundle string

	// Enables endpoint discovery via environment variables.
	//
	//	AWS_ENABLE_ENDPOINT_DISCOVERY=true
	EnableEndpointDiscovery *bool

	// Specifies the WebIdentity token the SDK should use to assume a role
	// with.
	//
	//  AWS_WEB_IDENTITY_TOKEN_FILE=file_path
	WebIdentityTokenFilePath string

	// Specifies the IAM role arn to use when assuming an role.
	//
	//  AWS_ROLE_ARN=role_arn
	RoleARN string

	// Specifies the IAM role session name to use when assuming a role.
	//
	//  AWS_ROLE_SESSION_NAME=session_name
	RoleSessionName string

	// Specifies if the S3 service should allow ARNs to direct the region
	// the client's requests are sent to.
	//
	// AWS_S3_USE_ARN_REGION=true
	S3UseARNRegion *bool
}

EnvConfig is a collection of environment values the SDK will read setup config from. All environment values are optional. But some values such as credentials require multiple values to be complete or the values will be ignored.

func NewEnvConfig

func NewEnvConfig() (EnvConfig, error)

NewEnvConfig retrieves the SDK's environment configuration. See `EnvConfig` for the values that will be retrieved.

func (EnvConfig) GetCustomCABundle

func (c EnvConfig) GetCustomCABundle() ([]byte, error)

GetCustomCABundle returns the custom CA bundle's PEM bytes if the file was

func (EnvConfig) GetEnableEndpointDiscovery

func (c EnvConfig) GetEnableEndpointDiscovery() (value, ok bool, err error)

GetEnableEndpointDiscovery returns whether to enable service endpoint discovery

func (EnvConfig) GetRegion

func (c EnvConfig) GetRegion() (string, error)

GetRegion returns the AWS Region if set in the environment. Returns an empty string if not set.

func (EnvConfig) GetS3UseARNRegion

func (c EnvConfig) GetS3UseARNRegion() (value, ok bool, err error)

GetS3UseARNRegion returns whether to allow ARNs to direct the region the S3 client's requests are sent to.

func (EnvConfig) GetSharedConfigFiles

func (c EnvConfig) GetSharedConfigFiles() ([]string, error)

GetSharedConfigFiles returns a slice of filenames set in the environment.

Will return the filenames in the order of: * Shared Credentials * Shared Config

func (EnvConfig) GetSharedConfigProfile

func (c EnvConfig) GetSharedConfigProfile() (string, error)

GetSharedConfigProfile returns the shared config profile if set in the environment. Returns an empty string if not set.

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient is an HTTP client implementation

type HTTPClientProvider

type HTTPClientProvider interface {
	GetHTTPClient() (HTTPClient, bool, error)
}

HTTPClientProvider is an interface for retrieving an HTTPClient.

func WithHTTPClient

func WithHTTPClient(client HTTPClient) HTTPClientProvider

WithHTTPClient wraps a HTTPClient and satisfies the HTTPClientProvider interface

Example
package main

import (
	"log"
	"net/http"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
)

func main() {
	cfg, err := config.LoadDefaultConfig(config.WithHTTPClient(
		aws.NewBuildableHTTPClient().WithTransportOptions(func(tr *http.Transport) {
			tr.MaxIdleConns = 60
		})))
	if err != nil {
		log.Fatal(err)
	}
	_ = cfg
}
Output:

type ProcessCredentialOptions

type ProcessCredentialOptions interface {
	GetProcessCredentialOptions() (func(*processcreds.Options), bool, error)
}

ProcessCredentialOptions is an interface for retrieving a function for setting the processcreds.Options.

type RegionProvider

type RegionProvider interface {
	GetRegion() (string, error)
}

RegionProvider provides access to the region external configuration value.

type SharedConfig

type SharedConfig struct {
	Profile string

	// Credentials values from the config file. Both aws_access_key_id
	// and aws_secret_access_key must be provided together in the same file
	// to be considered valid. The values will be ignored if not a complete group.
	// aws_session_token is an optional field that can be provided if both of the
	// other two fields are also provided.
	//
	//	aws_access_key_id
	//	aws_secret_access_key
	//	aws_session_token
	Credentials aws.Credentials

	CredentialSource     string
	CredentialProcess    string
	WebIdentityTokenFile string

	RoleARN             string
	ExternalID          string
	MFASerial           string
	RoleSessionName     string
	RoleDurationSeconds *time.Duration

	SourceProfileName string
	Source            *SharedConfig

	// Region is the region the SDK should use for looking up AWS service endpoints
	// and signing requests.
	//
	//	region
	Region string

	// EnableEndpointDiscovery can be enabled in the shared config by setting
	// endpoint_discovery_enabled to true
	//
	//	endpoint_discovery_enabled = true
	EnableEndpointDiscovery *bool

	// Specifies if the S3 service should allow ARNs to direct the region
	// the client's requests are sent to.
	//
	// s3_use_arn_region=true
	S3UseARNRegion *bool
}

SharedConfig represents the configuration fields of the SDK config files.

func NewSharedConfig

func NewSharedConfig(profile string, filenames []string) (SharedConfig, error)

NewSharedConfig retrieves the configuration from the list of files using the profile provided. The order the files are listed will determine precedence. Values in subsequent files will overwrite values defined in earlier files.

For example, given two files A and B. Both define credentials. If the order of the files are A then B, B's credential values will be used instead of A's.

func (SharedConfig) GetCredentialsProvider

func (c SharedConfig) GetCredentialsProvider() (aws.Credentials, error)

GetCredentialsProvider returns the credentials for a profile if they were set.

func (*SharedConfig) GetEnableEndpointDiscovery

func (c *SharedConfig) GetEnableEndpointDiscovery() (value, ok bool, err error)

GetEnableEndpointDiscovery returns whether to enable service endpoint discovery

func (SharedConfig) GetRegion

func (c SharedConfig) GetRegion() (string, error)

GetRegion returns the region for the profile if a region is set.

func (*SharedConfig) GetS3UseARNRegion

func (c *SharedConfig) GetS3UseARNRegion() (value, ok bool, err error)

GetS3UseARNRegion returns if the S3 service should allow ARNs to direct the region the client's requests are sent to.

type SharedConfigAssumeRoleError

type SharedConfigAssumeRoleError struct {
	Profile string
	RoleARN string
	Err     error
}

SharedConfigAssumeRoleError is an error for the shared config when the profile contains assume role information, but that information is invalid or not complete.

func (SharedConfigAssumeRoleError) Error

func (SharedConfigAssumeRoleError) Unwrap

Unwrap returns the underlying error that caused the failure.

type SharedConfigFileNotExistError

type SharedConfigFileNotExistError struct {
	Filename string
	Profile  string
	Err      error
}

SharedConfigFileNotExistError is an error for the shared config when the filename does not exist.

func (SharedConfigFileNotExistError) Error

func (SharedConfigFileNotExistError) Unwrap

Unwrap returns the underlying error that caused the failure.

type SharedConfigFilesProvider

type SharedConfigFilesProvider interface {
	GetSharedConfigFiles() ([]string, error)
}

SharedConfigFilesProvider provides access to the shared config filesnames external configuration value.

type SharedConfigLoadError

type SharedConfigLoadError struct {
	Filename string
	Err      error
}

SharedConfigLoadError is an error for the shared config file failed to load.

func (SharedConfigLoadError) Error

func (e SharedConfigLoadError) Error() string

func (SharedConfigLoadError) Unwrap

func (e SharedConfigLoadError) Unwrap() error

Unwrap returns the underlying error that caused the failure.

type SharedConfigNotExistErrors

type SharedConfigNotExistErrors []error

SharedConfigNotExistErrors provides an error type for failure to load shared config because resources do not exist.

func (SharedConfigNotExistErrors) Error

type SharedConfigProfileNotExistError

type SharedConfigProfileNotExistError struct {
	Filename string
	Profile  string
	Err      error
}

SharedConfigProfileNotExistError is an error for the shared config when the profile was not find in the config file.

func (SharedConfigProfileNotExistError) Error

func (SharedConfigProfileNotExistError) Unwrap

Unwrap returns the underlying error that caused the failure.

type SharedConfigProfileProvider

type SharedConfigProfileProvider interface {
	GetSharedConfigProfile() (string, error)
}

SharedConfigProfileProvider provides access to the shared config profile name external configuration value.

type WebIdentityRoleCredentialOptionsProvider added in v0.2.0

type WebIdentityRoleCredentialOptionsProvider interface {
	GetWebIdentityRoleCredentialOptions() (func(*stscreds.WebIdentityRoleOptions), bool, error)
}

WebIdentityRoleCredentialOptionsProvider is an interface for retrieving a function for setting the stscreds.WebIdentityRoleProvider.

type WithAPIOptions

type WithAPIOptions []func(*middleware.Stack) error

WithAPIOptions wraps a slice of middlewares stack mutators and satisfies the APIOptionsProvider interface.

Example
package main

import (
	"log"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/awslabs/smithy-go/middleware"

	smithyhttp "github.com/awslabs/smithy-go/transport/http"
)

func main() {
	// import "github.com/awslabs/smithy-go/middleware"
	// import smithyhttp "github.com/awslabs/smithy-go/transport/http"

	cfg, err := config.LoadDefaultConfig(config.WithAPIOptions([]func(stack *middleware.Stack) error{
		smithyhttp.AddHeaderValue("X-Custom-Header", "customHeaderValue"),
	}))
	if err != nil {
		log.Fatal(err)
	}
	_ = cfg
}
Output:

func (WithAPIOptions) GetAPIOptions

func (w WithAPIOptions) GetAPIOptions() ([]func(*middleware.Stack) error, bool, error)

GetAPIOptions returns the wrapped middleware stack mutators.

type WithAssumeRoleCredentialOptions added in v0.2.0

type WithAssumeRoleCredentialOptions func(*stscreds.AssumeRoleOptions)

WithAssumeRoleCredentialOptions wraps a function and satisfies the EC2RoleCredentialOptionsProvider interface

Example
package main

import (
	"log"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
)

func main() {
	// WithAssumeRoleCredentialOptions can be used to configure the AssumeRoleOptions for the STS credential provider.
	// For example the TokenProvider can be populated if assuming a role that requires an MFA token.
	cfg, err := config.LoadDefaultConfig(config.WithAssumeRoleCredentialOptions(func(options *stscreds.AssumeRoleOptions) {
		options.TokenProvider = func() (string, error) {
			return "theTokenCode", nil
		}
	}))
	if err != nil {
		log.Fatal(err)
	}
	_ = cfg
}
Output:

func (WithAssumeRoleCredentialOptions) GetAssumeRoleCredentialOptions added in v0.2.0

func (w WithAssumeRoleCredentialOptions) GetAssumeRoleCredentialOptions() (func(*stscreds.AssumeRoleOptions), bool, error)

GetAssumeRoleCredentialOptions returns the wrapped function

type WithCustomCABundle

type WithCustomCABundle []byte

WithCustomCABundle provides wrapping of a region string to satisfy the CustomCABundleProvider interface.

func (WithCustomCABundle) GetCustomCABundle

func (v WithCustomCABundle) GetCustomCABundle() ([]byte, error)

GetCustomCABundle returns the CA bundle PEM bytes.

type WithDefaultRegion

type WithDefaultRegion string

WithDefaultRegion wraps a string and satisfies the DefaultRegionProvider interface

func (WithDefaultRegion) GetDefaultRegion

func (w WithDefaultRegion) GetDefaultRegion() (string, bool, error)

GetDefaultRegion returns wrapped fallback region

type WithEC2IMDSRegion

type WithEC2IMDSRegion struct {
	// If unset will be defaulted to Background context
	Context context.Context

	// If unset will default to generic EC2 IMDS client.
	Client *ec2imds.Client
}

WithEC2IMDSRegion provides a RegionProvider that retrieves the region from the EC2 Metadata service.

TODO should this provider be added to the default config loading?

Example
package main

import (
	"log"

	"github.com/aws/aws-sdk-go-v2/config"
)

func main() {
	cfg, err := config.LoadDefaultConfig(config.WithEC2IMDSRegion{})
	if err != nil {
		log.Fatal(err)
	}
	_ = cfg
}
Output:

func (WithEC2IMDSRegion) GetRegion

func (p WithEC2IMDSRegion) GetRegion() (string, error)

GetRegion attempts to retrieve the region from EC2 Metadata service.

type WithEC2RoleCredentialOptions added in v0.2.0

type WithEC2RoleCredentialOptions func(*ec2rolecreds.Options)

WithEC2RoleCredentialOptions wraps a function and satisfies the EC2RoleCredentialOptionsProvider interface

func (WithEC2RoleCredentialOptions) GetEC2RoleCredentialOptions added in v0.2.0

func (w WithEC2RoleCredentialOptions) GetEC2RoleCredentialOptions() (func(*ec2rolecreds.Options), bool, error)

GetEC2RoleCredentialOptions returns the wrapped function

type WithEndpointCredentialOptions added in v0.2.0

type WithEndpointCredentialOptions func(*endpointcreds.Options)

WithEndpointCredentialOptions wraps a function and satisfies the EC2RoleCredentialOptionsProvider interface

func (WithEndpointCredentialOptions) GetEndpointCredentialOptions added in v0.2.0

func (w WithEndpointCredentialOptions) GetEndpointCredentialOptions() (func(*endpointcreds.Options), bool, error)

GetEndpointCredentialOptions returns the wrapped function

type WithProcessCredentialOptions

type WithProcessCredentialOptions func(*processcreds.Options)

WithProcessCredentialOptions wraps a function and satisfies the ProcessCredentialOptions interface

func (WithProcessCredentialOptions) GetProcessCredentialOptions

func (w WithProcessCredentialOptions) GetProcessCredentialOptions() (func(*processcreds.Options), bool, error)

GetProcessCredentialOptions returns the wrapped function

type WithRegion

type WithRegion string

WithRegion provides wrapping of a region string to satisfy the RegionProvider interface.

Example
package main

import (
	"log"

	"github.com/aws/aws-sdk-go-v2/config"
)

func main() {
	cfg, err := config.LoadDefaultConfig(config.WithRegion("us-west-2"))
	if err != nil {
		log.Fatal(err)
	}
	_ = cfg
}
Output:

func (WithRegion) GetRegion

func (v WithRegion) GetRegion() (string, error)

GetRegion returns the region string.

type WithSharedConfigFiles

type WithSharedConfigFiles []string

WithSharedConfigFiles wraps a slice of strings to satisfy the SharedConfigFilesProvider interface so a slice of custom shared config files are used when loading the SharedConfig.

func (WithSharedConfigFiles) GetSharedConfigFiles

func (c WithSharedConfigFiles) GetSharedConfigFiles() ([]string, error)

GetSharedConfigFiles returns the slice of shared config files.

type WithSharedConfigProfile

type WithSharedConfigProfile string

WithSharedConfigProfile wraps a strings to satisfy the SharedConfigProfileProvider interface so a slice of custom shared config files ared used when loading the SharedConfig.

Example
package main

import (
	"fmt"
	"log"
	"path/filepath"

	"github.com/aws/aws-sdk-go-v2/config"
)

func main() {
	cfg, err := config.LoadDefaultConfig(
		// Specify the shared configuration profile to load.
		config.WithSharedConfigProfile("exampleProfile"),

		// Optionally specify the specific shared configuraiton
		// files to load the profile from.
		config.WithSharedConfigFiles([]string{
			filepath.Join("testdata", "shared_config"),
		}),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Region loaded from credentials file.
	fmt.Println("Region:", cfg.Region)

}
Output:

Region: us-west-2

func (WithSharedConfigProfile) GetSharedConfigProfile

func (c WithSharedConfigProfile) GetSharedConfigProfile() (string, error)

GetSharedConfigProfile returns the shared config profile.

type WithWebIdentityRoleCredentialOptions added in v0.2.0

type WithWebIdentityRoleCredentialOptions func(*stscreds.WebIdentityRoleOptions)

WithWebIdentityRoleCredentialOptions wraps a function and satisfies the EC2RoleCredentialOptionsProvider interface

Example
package main

import (
	"log"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
)

func main() {
	cfg, err := config.LoadDefaultConfig(config.WithWebIdentityRoleCredentialOptions(func(options *stscreds.WebIdentityRoleOptions) {
		options.RoleSessionName = "customSessionName"
	}))
	if err != nil {
		log.Fatal(err)
	}
	_ = cfg
}
Output:

func (WithWebIdentityRoleCredentialOptions) GetWebIdentityRoleCredentialOptions added in v0.2.0

func (w WithWebIdentityRoleCredentialOptions) GetWebIdentityRoleCredentialOptions() (func(*stscreds.WebIdentityRoleOptions), bool, error)

GetWebIdentityRoleCredentialOptions returns the wrapped function

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL