【问题标题】:I set my AWS keys and they show up in linux terminal, but Rails 4 app can't find them. Using aws-sdk and carrierwave-aws gems我设置了我的 AWS 密钥,它们显示在 linux 终端中,但 Rails 4 应用程序找不到它们。使用 aws-sdk 和carrierwave-aws gem
【发布时间】:2015-01-25 07:25:43
【问题描述】:

这是我的载波配置文件:

CarrierWave.configure do |config|
  config.storage    = :aws
  config.aws_bucket = ENV.fetch('S3_BUCKET_NAME')
  config.aws_acl    = :public_read
  config.asset_host = 'http://example.com'

config.aws_credentials = {
  access_key_id:     ENV.fetch('AWS_ACCESS_KEY_ID'),
  secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY')

}

结束

服务器不会启动并返回:

14:53:23 web.1 | /home/tom/paul/config/initializers/carrierwave.rb:9:in `fetch': key not found: "AWS_ACCESS_KEY_ID" (KeyError)

我在命令行中输入了这样的键:

export AWS_ACCESS_KEY_ID="demo12345"

加引号和不加引号

命令

env

正常显示

【问题讨论】:

    标签: ruby-on-rails amazon-s3 env


    【解决方案1】:

    我会使用 Gem 'Figaro' 来帮助管理环境变量。非常容易设置和管理。

    1) 添加到您的 Gemfile 和捆绑包中:

    gem 'figaro', '1.0'
    

    2) 运行“figaro 安装”

    figaro install
    

    3) 打开生成的文件:config/application.yml 并添加变量:

    SAMPLE_PASSWORD: exAmplePa$$
    SAMPLE_USERNAME: myspecialusername
    

    4) 回到你的初始化文件并改变你的变量:

    user_name:      ENV['SAMPLE_USERNAME'],
    password:       ENV['SAMPLE_PASSWORD'],
    

    你应该很高兴!

    【讨论】:

      【解决方案2】:

      您应该在 config/environments/development.rb 中更改/编辑 因为它:

      S3_BUCKET_NAME=    ******your bucket name ****
      AWS_ACCESS_KEY_ID= ******your acess key_id***
      AWS_SECRET_ACCESS_KEY= ********* your secret key ***
      AWS_REGION=            ******* your region ***
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-03
        • 2020-04-18
        • 1970-01-01
        • 2021-12-12
        • 1970-01-01
        • 2019-09-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多