You must specify a region. You can also configure your region by running 'aws configure'
What causes this
The AWS CLI or SDK doesn’t know which AWS region to send your request to. Every AWS API call targets a specific region, and if none is configured, the request fails.
This happens when:
- You never ran
aws configureafter installing the CLI - The
AWS_DEFAULT_REGIONenvironment variable isn’t set - Your
~/.aws/configfile is missing or doesn’t have a region for the active profile - You’re using a named profile that doesn’t have a region configured
- Your CI/CD environment doesn’t set the region
Fix 1: Set the region with aws configure
aws configure
# AWS Access Key ID: (enter your key)
# AWS Secret Access Key: (enter your secret)
# Default region name: us-east-1
# Default output format: json
This writes to ~/.aws/config and ~/.aws/credentials.
Fix 2: Pass the region flag directly
aws s3 ls --region us-east-1
aws ec2 describe-instances --region eu-west-1
This overrides any configured default for that single command.
Fix 3: Set the environment variable
# For the current session
export AWS_DEFAULT_REGION=us-east-1
# Or permanently in your shell config
echo 'export AWS_DEFAULT_REGION=us-east-1' >> ~/.bashrc
source ~/.bashrc
For zsh:
echo 'export AWS_DEFAULT_REGION=us-east-1' >> ~/.zshrc
source ~/.zshrc
Fix 4: Configure a named profile
# ~/.aws/config
[default]
region = us-east-1
[profile staging]
region = eu-west-1
[profile production]
region = us-east-1
Use a profile:
aws s3 ls --profile staging
# or
export AWS_PROFILE=staging
Fix 5: Set region in your SDK code
If you’re using the AWS SDK in code:
// AWS SDK v3 (JavaScript)
import { S3Client } from '@aws-sdk/client-s3';
const client = new S3Client({ region: 'us-east-1' });
# boto3 (Python)
import boto3
client = boto3.client('s3', region_name='us-east-1')
Fix 6: Fix CI/CD environments
In GitHub Actions:
env:
AWS_DEFAULT_REGION: us-east-1
In Docker:
ENV AWS_DEFAULT_REGION=us-east-1
How to prevent it
- Always run
aws configureright after installing the AWS CLI - Set
AWS_DEFAULT_REGIONin your shell profile as a fallback - In CI/CD, always explicitly set the region — don’t rely on defaults
- Use named profiles for different environments so each has its own region
- When writing SDK code, always pass the region explicitly rather than relying on environment config