9

I get the following warning while querying Amazon S3 via the Fog gem:

[WARNING] fog: followed redirect to my-bucket.s3-external-3.amazonaws.com, connecting to the matching region will be more performant

How exactly do I "connect to the matching region"?

clozach
  • 5,118
  • 5
  • 41
  • 54

1 Answers1

12

Set the :region option in the Fog connection parameters to the name of the region in which your bucket exists.

For example, I have a bucket called "bucket-a" in region "eu-west-1" and my s3 key and secret are in variables s3_key and s3_secret respectively.

I can connect to this region directly by opening my Fog connection as follows:

s3 = Fog::Storage.new(provider: 'AWS', aws_access_key_id: s3_key, aws_secret_access_key: s3_secret, region: 'eu-west-1')

And now when I list the contents, no region warning is issued:

s3.directories.get('bucket-a').files

If you want to do this for all your buckets, rather than on a bucket-by-bucket basis you can set the following:

Fog::Storage::AWS::DEFAULT_REGION = 'eu-west-1'
Jim Riordan
  • 1,378
  • 11
  • 18
  • I am using [sitemap_generator](https://github.com/kjvarga/sitemap_generator) gem with s3adapter in a rails 3.2 app. [sitemap_generator](https://github.com/kjvarga/sitemap_generator) uses fog internally. Despite of adding `region: 'ap-southeast-1'` parameter to the hash, I continue to get the warning @clozach has mentioned – Litmus Jul 08 '13 at 05:07
  • what version of sitemap_generator are you using? – Jim Riordan Jul 08 '13 at 16:49
  • sitemap_generator-4.1.0. The hash key is called `fog_region`, which ultimately gets passed on to fog as `region`. `{aws_access_key_id: , aws_secret_access_key: , fog_provider: 'AWS', fog_directory: , fog_region: 'ap-southeast-1'}` – Litmus Jul 10 '13 at 08:45
  • 1
    Use `Fog::Storage::AWS.send(:remove_const, 'DEFAULT_REGION') Fog::Storage::AWS::DEFAULT_REGION = 'eu-west-1'` To avoid the warning. – Karl Glaser Mar 13 '14 at 01:21