Skip to content

Configured region is ignored in the string and positional constructor forms #595

Description

@AdrianCurtin

New Issue Checklist

Issue Description

region passed in the options object is silently discarded when the adapter is constructed with the string or positional forms. The adapter falls back to us-east-1, so both the S3 client and the generated file urls address the wrong region, with no warning.

optionsFromArguments copies an explicit list of fields out of the options object for those two forms:

if (otherOptions) {
  options.bucketPrefix = otherOptions.bucketPrefix;
  options.credentials = otherOptions.credentials;
  options.directAccess = otherOptions.directAccess;
  // ...
}

region is the only field in the defaults list further down that is missing from that copy list, so it never survives to fromEnvironmentOrDefault(options, 'region', 'S3_REGION', DEFAULT_S3_REGION) and takes the default.

Steps to reproduce

new S3Adapter('key', 'secret', 'bucket', { region: 'ap-east-1' })._region;
new S3Adapter('bucket', { region: 'ap-east-1' })._region;
new S3Adapter({ bucket: 'bucket', region: 'ap-east-1' })._region;

Actual Outcome

Constructor form _region
('key', 'secret', 'bucket', { region }) us-east-1
('bucket', { region }) us-east-1
({ bucket, region }) ap-east-1

Expected Outcome

All three resolve to ap-east-1. region should behave like every other option, explicit value first, then S3_REGION, then the default.

Notes

The failure is silent, which is what makes it costly to diagnose. A bucket outside us-east-1 rejects writes with PermanentRedirect, and the reporter of #139 is a plausible instance: uploads worked, so their region did reach the client, meaning they used the object form or S3_REGION, while anyone on the positional form would see a different and more confusing failure.

Found while fixing #139. Both are the same underlying symptom, the configured region not being honored, so they are fixed together in the PR that closes this.

Environment

Adapter version: master, current lib/optionsFromArguments.js.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions