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

environment-configuration.mddocs/

Environment Configuration

The environment configuration capability provides access to AWS SDK configuration values from environment variables.

Overview

The EnvConfig type contains configuration values read from environment variables. All environment values are optional, but some values such as credentials require multiple values to be complete or they will be ignored.

API

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)

EnvConfig Fields

Credentials

Static credentials from environment variables:

  • AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY - Access key ID
  • AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY - Secret access key
  • AWS_SESSION_TOKEN - Session token (optional)

Container Credentials

  • ContainerCredentialsEndpoint - HTTP endpoint to retrieve credentials using the endpointcreds.Provider
  • ContainerCredentialsRelativePath - Relative URI path for container endpoint
  • ContainerAuthorizationToken - Authorization token for HTTP Authorization header

Region

  • Region - AWS region from AWS_REGION or AWS_DEFAULT_REGION

Shared Configuration

  • SharedConfigProfile - Profile name from AWS_PROFILE or AWS_DEFAULT_PROFILE
  • SharedCredentialsFile - Custom credentials file path from AWS_SHARED_CREDENTIALS_FILE
  • SharedConfigFile - Custom config file path from AWS_CONFIG_FILE

TLS/SSL

  • CustomCABundle - Custom CA Bundle path from AWS_CA_BUNDLE

Web Identity

  • WebIdentityTokenFilePath - Web identity token file from AWS_WEB_IDENTITY_TOKEN_FILE
  • RoleARN - IAM role ARN from AWS_ROLE_ARN
  • RoleSessionName - IAM role session name from AWS_ROLE_SESSION_NAME

S3 Configuration

  • S3UseARNRegion - Allow S3 ARNs to direct region from AWS_S3_USE_ARN_REGION
  • S3DisableMultiRegionAccessPoints - Disable S3 multi-region access points from AWS_S3_DISABLE_MULTIREGION_ACCESS_POINTS
  • S3DisableExpressAuth - Disable S3 Express auth

EC2 Instance Metadata

  • EC2IMDSClientEnableState - Enable/disable EC2 IMDS from AWS_EC2_METADATA_DISABLED
  • EC2IMDSv1Disabled - Disable IMDSv1 fallback from AWS_EC2_METADATA_V1_DISABLED
  • EC2IMDSEndpointMode - IMDS endpoint mode (IPv4/IPv6) from AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE
  • EC2IMDSEndpoint - IMDS endpoint URL from AWS_EC2_METADATA_SERVICE_ENDPOINT

Endpoint Configuration

  • EnableEndpointDiscovery - Enable endpoint discovery from AWS_ENABLE_ENDPOINT_DISCOVERY
  • UseDualStackEndpoint - Use dual-stack endpoints from AWS_USE_DUALSTACK_ENDPOINT
  • UseFIPSEndpoint - Use FIPS endpoints from AWS_USE_FIPS_ENDPOINT
  • IgnoreConfiguredEndpoints - Disable configured endpoints
  • BaseEndpoint - Base endpoint URL

SDK Configuration

  • DefaultsMode - SDK defaults mode from AWS_DEFAULTS_MODE
  • RetryMaxAttempts - Max retry attempts from AWS_MAX_ATTEMPTS
  • RetryMode - Retry mode from AWS_RETRY_MODE
  • AppID - SDK app ID for user agent
  • DisableRequestCompression - Disable request compression from AWS_DISABLE_REQUEST_COMPRESSION
  • RequestMinCompressSizeBytes - Min size for compression from AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES
  • AccountIDEndpointMode - Account ID endpoint mode

EnvConfig Methods

func (c EnvConfig) GetEC2IMDSClientEnableState() (imds.ClientEnableState, bool, error)

func (c EnvConfig) GetEC2IMDSEndpoint() (string, bool, error)

func (c EnvConfig) GetEC2IMDSEndpointMode() (imds.EndpointModeState, bool, error)

func (c EnvConfig) GetEC2IMDSV1FallbackDisabled() (bool, bool)

func (c EnvConfig) GetEnableEndpointDiscovery(ctx context.Context) (value aws.EndpointDiscoveryEnableState, found bool, err error)

func (c EnvConfig) GetIgnoreConfiguredEndpoints(context.Context) (bool, bool, error)

func (c EnvConfig) GetRetryMaxAttempts(ctx context.Context) (int, bool, error)

func (c EnvConfig) GetRetryMode(ctx context.Context) (aws.RetryMode, bool, error)

func (c EnvConfig) GetS3DisableExpressAuth() (value, ok bool)

func (c EnvConfig) GetS3DisableMultiRegionAccessPoints(ctx context.Context) (value, ok bool, err error)

func (c EnvConfig) GetS3UseARNRegion(ctx context.Context) (value, ok bool, err error)

func (c EnvConfig) GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error)

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

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

Usage

Retrieving Environment Configuration

package main

import (
    "fmt"
    "log"

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

func main() {
    envConfig, err := config.NewEnvConfig()
    if err != nil {
        log.Fatalf("unable to load environment config, %v", err)
    }

    fmt.Printf("Region from environment: %s\n", envConfig.Region)
    fmt.Printf("Profile from environment: %s\n", envConfig.SharedConfigProfile)
}

Checking Environment Values

import (
    "context"
)

envConfig, err := config.NewEnvConfig()
if err != nil {
    log.Fatal(err)
}

// Check if retry max attempts is set
if maxAttempts, found, err := envConfig.GetRetryMaxAttempts(context.TODO()); found && err == nil {
    fmt.Printf("Max retry attempts: %d\n", maxAttempts)
}

// Check if S3 ARN region is enabled
if useARNRegion, found, err := envConfig.GetS3UseARNRegion(context.TODO()); found && err == nil {
    fmt.Printf("S3 Use ARN Region: %v\n", useARNRegion)
}

Environment Variables Reference

Environment VariableEnvConfig FieldDescription
AWS_ACCESS_KEY_IDCredentials.AccessKeyIDAWS access key ID
AWS_SECRET_ACCESS_KEYCredentials.SecretAccessKeyAWS secret access key
AWS_SESSION_TOKENCredentials.SessionTokenAWS session token
AWS_REGIONRegionAWS region
AWS_DEFAULT_REGIONRegionAWS region (fallback)
AWS_PROFILESharedConfigProfileShared config profile name
AWS_DEFAULT_PROFILESharedConfigProfileProfile name (fallback)
AWS_SHARED_CREDENTIALS_FILESharedCredentialsFileCustom credentials file path
AWS_CONFIG_FILESharedConfigFileCustom config file path
AWS_CA_BUNDLECustomCABundleCustom CA bundle path
AWS_ENABLE_ENDPOINT_DISCOVERYEnableEndpointDiscoveryEnable endpoint discovery
AWS_WEB_IDENTITY_TOKEN_FILEWebIdentityTokenFilePathWeb identity token file
AWS_ROLE_ARNRoleARNIAM role ARN
AWS_ROLE_SESSION_NAMERoleSessionNameIAM role session name
AWS_S3_USE_ARN_REGIONS3UseARNRegionAllow S3 ARNs to direct region
AWS_EC2_METADATA_DISABLEDEC2IMDSClientEnableStateDisable EC2 IMDS
AWS_EC2_METADATA_V1_DISABLEDEC2IMDSv1DisabledDisable IMDSv1 fallback
AWS_EC2_METADATA_SERVICE_ENDPOINT_MODEEC2IMDSEndpointModeIMDS endpoint mode
AWS_EC2_METADATA_SERVICE_ENDPOINTEC2IMDSEndpointIMDS endpoint URL
AWS_S3_DISABLE_MULTIREGION_ACCESS_POINTSS3DisableMultiRegionAccessPointsDisable S3 multi-region access points
AWS_USE_DUALSTACK_ENDPOINTUseDualStackEndpointUse dual-stack endpoints
AWS_USE_FIPS_ENDPOINTUseFIPSEndpointUse FIPS endpoints
AWS_DEFAULTS_MODEDefaultsModeSDK defaults mode
AWS_MAX_ATTEMPTSRetryMaxAttemptsMax retry attempts
AWS_RETRY_MODERetryModeRetry mode
AWS_DISABLE_REQUEST_COMPRESSIONDisableRequestCompressionDisable request compression
AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTESRequestMinCompressSizeBytesMin compression size

Constants

const CredentialsSourceName = "EnvConfigCredentials"

Provides the name of the provider when config is loaded from environment.