I am trying to set up my rails app to upload its assets to Amazon's AWS S3 using the asset_sync gem, following these instructions. I know I've got my S3 stuff configured right because my app is otherwise able to upload images to S3. I'm pretty sure I've got all the settings correct:
FOG_DIRECTORY => mybucketname
FOG_PROVIDER => AWS
FOG_REGION => s3-us-west-2
Yet I keep getting an error:
-bash> heroku run rake assets:precompile --remote staging
Running rake assets:precompile attached to terminal... up, run.1
AssetSync: using default configuration from built-in initializer
mkdir -p /app/public/assets
...
mkdir -p /app/public/assets
AssetSync: Syncing.
rake aborted!
getaddrinfo: Name or service not known # <-- error
Compiling locally produces a slightly different error:
-bash> bundle exec rake assets:precompile
AssetSync: using default configuration from built-in initializer
mkdir -p /Users/bart/Dev/MyApp/myapp/public/assets
...
mkdir -p /Users/bart/Dev/MyApp/myapp/public/assets
AssetSync: Syncing.
rake aborted!
getaddrinfo: nodename nor servname provided, or not known # <-- error
I traced the error down to a 'connection' line in Fog, one of asset_sync
's runtime dependencies, and it turns out that my FOG_REGION
was set incorrectly. In my case, the region should have been us-west-2
, not s3-us-west-2
.
It has been a while since I configured my S3 account, so I first tried to determine what region I was using by logging into the AWS S3 console, clicking on the bucket name, and then clicking "Properties". There, the region is listed as Oregon. Well, that didn't work. So then I clicked through the objects and folders browser of one of my existing buckets until I got to an asset, looked up its "Properties", and saw the "Link":
https://s3-us-west-2.amazonaws.com/mybucketname/uploads/mymodel/image/1135/myimage.jpg
I was convinced that s3-us-west-2
was correct until I noticed that Fog adds the s3- prefix.
Anyway, I now know that once you find out your region by name (e.g. Oregon), you can look it up in this list of S3 regions (it's the name under the column Location Constraint).
I hope this helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With