Nov 20, 20265 min read

Fix "Missing Region" Errors in the AWS SDK

What "Region is missing", "NoRegionError: You must specify a region" and "Invalid Configuration: Missing Region" mean in the JavaScript, Python and Go AWS SDKs, where each SDK looks for a region, and why AWS_REGION alone does not fix boto3.

Illustration for Fix "Missing Region" Errors in the AWS SDK

Every AWS API call goes to a regional endpoint, so a client with no region fails before sending anything. JavaScript v3 says Region is missing, boto3 raises NoRegionError, and Go v2 reports Invalid Configuration: Missing Region.

In nearly every case the code works on a laptop with a profile and fails in a container, a CI job or a test.

Missing region errors at a glance

SDKErrorRegion sources, in order
JavaScript v3Region is missingClient option, AWS_REGION, profile region, instance metadata
Python (boto3)NoRegionError: You must specify a region.region_name, AWS_DEFAULT_REGION, profile region, instance metadata
Go v2Invalid Configuration: Missing Regionconfig.WithRegion, AWS_REGION or AWS_DEFAULT_REGION, profile region, metadata only if enabled

I reproduced each error with credentials set and every region source removed, using @aws-sdk/client-s3 3.1173, boto3 1.44.7 and aws-sdk-go-v2 config v1.33.21.

Why does AWS_REGION not fix boto3?

AWS_REGION and AWS_DEFAULT_REGION are not interchangeable: the AWS SDKs reference guide lists AWS_REGION as the standard variable, but boto3 still reads AWS_DEFAULT_REGION, as its configuration guide shows. The JavaScript SDK goes the other way and ignores AWS_DEFAULT_REGION:

~
$ AWS_REGION=eu-west-1 python -c "import boto3; boto3.client('sqs')"botocore.exceptions.NoRegionError: You must specify a region.$ AWS_DEFAULT_REGION=eu-west-1 python -c "import boto3; print(boto3.client('sqs').meta.region_name)"eu-west-1$ AWS_DEFAULT_REGION=eu-west-1 node list-buckets.mjsError Region is missing

A Dockerfile or CI job that sets only one of them fixes one language and breaks the other. Setting both is the cheap fix for polyglot repos. Lambda sets both for every function, which is why the same code works there and fails elsewhere.

Why does it work locally but fail in Docker or CI?

On a laptop the region usually comes from ~/.aws/config, in the profile AWS_PROFILE points at. A container does not see that file unless you mount it, and a CI runner has no profile at all. Some setups also put credentials in ~/.aws/credentials and the region only in ~/.aws/config, so mounting only the credentials file gives you a working identity and no region.

In GitHub Actions, the aws-actions/configure-aws-credentials action takes a required aws-region input and exports it for later steps. A job that sets credentials through plain secrets instead needs the region set explicitly in env.

What about EC2 and Fargate?

On EC2, boto3 and recent JavaScript v3 releases fall back to the region in the instance metadata service. Go v2 only does that when you load config with config.WithEC2IMDSRegion(), per the Go SDK configuration guide. Fargate tasks have no EC2 instance metadata, so set AWS_REGION and AWS_DEFAULT_REGION in the task definition rather than relying on that fallback.

Should you hardcode the region?

Passing the region in code, S3Client({ region }), boto3.client("s3", region_name=...) or config.WithRegion(...), always works and is the right call for clients that must talk to a specific region, such as a replication job. For everything else it ties the code to one deployment. Read it from configuration so staging and production can live in different regions without a code change.

How does Encore set the region?

Encore

Encore brings infrastructure from code: a Go service declares the resources it uses, such as an object storage bucket, and Encore provisions them in your AWS account in the region you pick for the environment. The service code holds no region, endpoint or credentials, so there is no variable to forget in a container or CI job.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Encore provisions the infrastructure your application needs in your own AWS or GCP account.
Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create pricing --example=hello-world$ cd pricing && mkdir snapshots
// snapshots/snapshots.go package snapshots import ( "context" "encoding/json" "fmt" "time" "encore.dev/storage/objects" ) // S3 on AWS, Cloud Storage on GCP, a local bucket under `encore run`. // No region, endpoint or credentials in code: Encore supplies them per environment. var Snapshots = objects.NewBucket("pricing-snapshots", objects.BucketConfig{}) type SaveParams struct { Prices map[string]int `json:"prices"` } type SaveResponse struct { Key string `json:"key"` } //encore:api private method=POST path=/snapshots func Save(ctx context.Context, p *SaveParams) (*SaveResponse, error) { key := fmt.Sprintf("prices/%s.json", time.Now().UTC().Format("2006-01-02T15-04-05")) w := Snapshots.Upload(ctx, key, objects.WithUploadAttrs(objects.UploadAttrs{ ContentType: "application/json", })) if err := json.NewEncoder(w).Encode(p.Prices); err != nil { w.Abort(err) return nil, err } if err := w.Close(); err != nil { return nil, err } return &SaveResponse{Key: key}, nil }

encore run stores the snapshots in a local bucket, and on deploy the same service gets an S3 bucket in the environment's region, and Encore provisions an IAM role for the service. The AWS infrastructure docs list what else Encore creates, and connecting your cloud covers choosing the region.

A coding agent that adds a bucket or a topic declares it in Go and runs it locally straight away, with no region, endpoint or IAM policy to wire up in a separate change.

Best fit: Teams calling S3, SNS or SQS from several services who keep chasing region and credential configuration across laptops, CI and containers.

Frequently asked questions

Why does boto3 say You must specify a region when AWS_REGION is set?

boto3 reads AWS_DEFAULT_REGION, not AWS_REGION. Tested with boto3 1.44.7, a client created with only AWS_REGION set raises NoRegionError, and the same client works with AWS_DEFAULT_REGION. Set both in containers and CI so every SDK finds a region.

Which environment variable does the AWS JavaScript SDK v3 read for the region?

AWS_REGION. It ignores AWS_DEFAULT_REGION, then checks the region in your shared config profile, then the EC2 instance metadata service, and throws Region is missing if none of them answer.

Does the AWS SDK for Go v2 read AWS_DEFAULT_REGION?

Yes. config.LoadDefaultConfig accepts AWS_REGION or AWS_DEFAULT_REGION and the profile region. It does not ask the instance metadata service unless you pass config.WithEC2IMDSRegion().

How do Encore apps get their AWS region?

Encore apps declare resources such as buckets in code and never configure a region, endpoint or credentials for them. Encore supplies those per environment when it provisions the resources in your AWS account.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders