Question: I'm using carriervawe and fog with S3 bucket. I get the error in the title in development (when I run `rails s` or `rake db:migrate`) with the following code:

```
CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: "AWS",
    aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
  }
  config.asset_host = "http://xxx.cloudfront.net"
  config.fog_directory = 'xxx'
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
  config.storage = :fog
end

```

I've also tried using (as suggested [**here**](https://stackoverflow.com/questions/10366552/not-recognizning-env-variables-in-s3-yml-in-rails))

```
<%= ENV['AWS_ACCESS_KEY_ID'] %>

```

but I get this error:

```
syntax error, unexpected '<' (SyntaxError)

```

My variables are in application.yml file

```
AWS_ACCESS_KEY_ID:  AKIAIxxx...
AWS_SECRET_ACCESS_KEY:  1xxx...

```

Answer: 
Not sure why, but for some reason your environment variables are likely being evaluated to nil. I like to use the [figaro gem](https://github.com/laserlemon/figaro) to manage my environment variables.

Simply add

```
gem "figaro"

```

to your gemfile.

Then run

```
figaro install

```

which will create an application.yml file and add it to your .gitignore (very important for security reasons). After this, you should be able to add your AWS keys to application.yml and access them in your carrierwave config like your currently have.
If this is from the Michael Hartl tutorial, I solved my issues by renaming the initializer to carrierwave.rb instead of carrier\_wave.rb, as suggested in the tutorial. I then re-ran the git and Heroku commands and it worked on the Heroku production server.