Why is `rake assets:precompile` throwing "getaddrinfo: Name or service not known"? (re: asset_sync)
Asked Answered
I

1

7

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
Incontrollable answered 3/8, 2012 at 16:7 Comment(0)
I
10

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.

Incontrollable answered 3/8, 2012 at 16:7 Comment(1)
Great answer. Still can't understand why Amazon such a large company have a very poor UINewbold

© 2022 - 2024 — McMap. All rights reserved.