!aws.region
The !aws.region YAML function retrieves the AWS region from the current SDK configuration.
This is the region that would be used for AWS API calls.
Usage
The !aws.region function takes no parameters:
# Get the current AWS region
region: !aws.region
Arguments
This function takes no arguments. It uses the AWS credentials and configuration from the environment or the Atmos authentication context if configured.
How It Works
When processing the !aws.region YAML function, Atmos:
-
Loads AWS Configuration - Uses the standard AWS SDK credential resolution chain:
- Environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN) - Shared credentials file (
~/.aws/credentials) - Shared config file (
~/.aws/config) - EC2 Instance Metadata Service (IMDS)
- ECS Task credentials
- Web Identity Token credentials
- Environment variables (
-
Calls STS GetCallerIdentity - Makes an API call to retrieve the caller identity
-
Returns Region - Extracts and returns the region from the loaded AWS configuration
When using Atmos Authentication, the function automatically uses credentials
from the active identity. This enables seamless integration with SSO, assume role chains, and other
authentication methods configured in your atmos.yaml.
Caching
The !aws.region function shares its cache with other AWS identity functions
(!aws.account_id, !aws.caller_identity_arn, !aws.caller_identity_user_id). This means:
- All AWS identity functions share a single STS API call
- Results are cached per CLI invocation
- Different authentication contexts get separate cache entries
Atmos supports type-aware merging of YAML functions and concrete values, allowing them to coexist in the inheritance chain without type conflicts. See the full explanation: YAML Function Merging
Examples
Basic Usage
Provider Configuration
Resource Naming with Region
Combined with Other AWS Functions
Cross-Region Configuration
Region Resolution Order
The region is resolved in the following order:
- Atmos Auth Context - If using Atmos authentication with a region specified
- AWS_REGION environment variable
- AWS_DEFAULT_REGION environment variable
- Shared config file (
~/.aws/config) - Theregionsetting for the active profile - Instance metadata - For EC2 instances or ECS tasks
Error Handling
If the function fails to determine the AWS region (e.g., no credentials available, no region configured), Atmos will log an error and exit.
Common error scenarios:
- No AWS credentials configured
- No region specified in credentials, config, or environment
- Network connectivity issues (for STS call)
Considerations
- Requires valid AWS credentials - The function needs credentials to make the STS call
- Region must be configured - Either via environment, config file, or Atmos auth
- Performance - Results are cached and shared with other AWS identity functions
- IAM permissions - Requires
sts:GetCallerIdentitypermission
Related Functions
- !aws.account_id - Get the AWS account ID
- !aws.caller_identity_arn - Get the full ARN
- !aws.caller_identity_user_id - Get the user ID
- !aws.organization_id - Get the AWS Organization ID