View a markdown version of this page

Config files and named profiles - AWS SDK for Python

Developer Preview — This documentation covers the AWS SDK for Python, which is in Developer Preview and intended for evaluation and testing only. Do not use it for production workloads. For production applications, use the AWS SDK for Python (Boto3). To understand the differences between the two SDKs, see Choosing the right AWS SDK for Python.

Config files and named profiles

This page covers how the SDK reads shared AWS configuration files and how to use named profiles to manage different environments. It includes the following topics:

Shared config files

The SDK searches the shared AWS configuration files when looking for configuration values. These are the same files used by the AWS CLI and other AWS SDKs, so the SDK automatically reads any settings you configured there. The SDK reads from two files:

File Default location Env override
Config ~/.aws/config AWS_CONFIG_FILE
Credentials ~/.aws/credentials AWS_SHARED_CREDENTIALS_FILE

Both files use INI-style format. The config file requires the [profile ...] prefix (except for [default]); the credentials file uses bare section names. You can create multiple profiles (logical groups of configuration) by creating sections named [profile profile-name].

# ~/.aws/config [default] region = us-west-2 retry_mode = standard max_attempts = 3 [profile production] region = us-east-1 retry_mode = standard max_attempts = 10
# ~/.aws/credentials [default] aws_access_key_id = AKIAIOSFODNN7EXAMPLE aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Using named profiles

A named profile is a collection of settings stored in the shared AWS config file under a specific name. With profiles, you can maintain separate configurations for different environments (such as development, staging, and production) and switch between them without changing your code.

By default, the SDK uses the [default] profile. To use a different profile, pass the profile parameter to resolve():

config = await AsyncBedrockRuntimeConfig.resolve(profile="production")

Or set the AWS_PROFILE environment variable:

export AWS_PROFILE=production

Example config file with multiple profiles:

# ~/.aws/config [default] region = us-east-1 retry_mode = standard [profile production] region = us-west-2 retry_mode = standard max_attempts = 10 [profile staging] region = eu-west-1 endpoint_url = https://staging.internal.example.com

If the requested profile doesn't exist in the config file, a ProfileNotFoundError is raised with a message indicating where the profile name came from:

config = await AsyncBedrockRuntimeConfig.resolve(profile="typo") # raises ProfileNotFoundError: Profile 'typo' from profile argument was not found in config file.
export AWS_PROFILE=typo
config = await AsyncBedrockRuntimeConfig.resolve() # raises ProfileNotFoundError: Profile 'typo' from AWS_PROFILE environment variable was not found in config file.

The implicit "default" profile is exempt from this check. If no config file exists, the SDK simply uses defaults and environment variables without error.