3

Im using asset_sync gem to upload assets to Amazon S3 bucket. I used dotenv to store my keys and secret keys and deployed using capistrano to Amazon EC2. Everything was fine.

But when I moved the keys to .bash_profile on my server and added an initializer, asset upload failed with this error.

rake aborted!
Fog directory can't be blank, Aws access key can't be blank, Aws secret access key can't be blank

Please help me to figure out why the keys/secrets are not found.

Santhosh
  • 28,097
  • 9
  • 82
  • 87

1 Answers1

1

Basically means you've not set the ENV vars for your shell session. I guarantee if you run rake assets:precompile FOG_DIRECTORY=[your_dir] AWS_ACCESS_KEY_ID=[your_access_key] AWS_SECRET_ACCESS_KEY=[secret_access] you'll be able to perform the operation

The best recommendation I can give right now is to look in the /etc/environment file on your VM. If you have this file, you'll be able to set the system-wide variables which will get used each time you load your app

The problem is an issue between the assigning of ENVIRONMENT & SHELL variables - SHELL vars are only available in a specific shell session, whilst ENVIRONMENT vars are available throughout the system

I have not found how to declare shell-specific variables on the fly yet, by putting all the env vars inside /etc/environment it works for us

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • Hi Rich thanks for your answer, But the error occurs while deployment and capistrano does precompiling. Apart from these 3, I have many other variables set and all works fine. I will try ENVIRONMENT variable instead of a shell variable. – Santhosh May 05 '14 at 12:03
  • Yep it's the same issue we have - Capistrano doesn't have access to your SHELL vars. It's SSHing into your server & performing the action... hence why the vars aren't available – Richard Peck May 05 '14 at 12:04
  • Hey, setting the vars in `/etc/environment` didn't work either – Santhosh May 06 '14 at 06:42
  • How strange! Can you try logging into the server with SSH & then performing the `rake assets:precompile` task with the SHELL vars like I posted above? If that works, it's a problem with your environment, else its an issue with your rails app – Richard Peck May 06 '14 at 06:44