【问题标题】:Aws::Errors::MissingCredentialsError in PostsController#update with Paperclip and AWSPostsController#update 中的 Aws::Errors::MissingCredentialsError 使用 Paperclip 和 AWS
【发布时间】:2018-06-10 04:13:35
【问题描述】:

我已经为此工作了几个小时,但无法弄清楚。我跑了 git clean 然后意识到我的 s3.yml 文件被删除了。我创建了新密钥并将它们放在一个新的 s3.yml 文件中。我没有改变以前工作得很好的任何其他东西。我错过了什么?

我收到:Aws::Errors::MissingCredentialsError (unable to sign request without credentials set):

这是我的代码:

开发.rb

  config.paperclip_defaults = {
    storage: :s3,
    s3_region: 'us-east-1',
    bucket:'mybucket',
    s3_credentials: "#{Rails.root}/config/s3.yml"
  }

生产.rb

config.paperclip_defaults = {
      storage: :s3,
      s3_credentials: {
        bucket: ENV.fetch('S3_BUCKET_NAME'),
        access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
        secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
        s3_region: ENV.fetch('AWS_REGION'),
      }
    }
    # Secret key base for non-existent secrets.yml file
    config.secret_key_base = ENV["SECRET_KEY_BASE"]

s3.yml(带有新的访问密钥)

S3_BUCKET_NAME: mybucket
AWS_ACCESS_KEY_ID: ***
AWS_SECRET_ACCESS_KEY: ***
AWS_REGION: us-east-1

课后

class Post < ApplicationRecord
  belongs_to :user, counter_cache: true
  belongs_to :category

  validates :title, :presence => true
  validates :content, :presence => true

  has_attached_file :thumbnail, styles: {
      medium: '270x170#',
      large: '560x280#',
      large2: '540x340#'
    }

    # Validate the attached image is image/jpg, image/png, etc
    validates_attachment_content_type :thumbnail, :content_type => /\Aimage\/.*\Z/
end

【问题讨论】:

  • 哪个环境给你这个错误?开发还是产品?
  • @TheOni 开发

标签: ruby-on-rails amazon-web-services amazon-s3 paperclip aws-sdk


【解决方案1】:

当您在开发环境中收到错误时,我认为该错误是由于 s3_credentials: "#{Rails.root}/config/s3.yml" 造成的。

鉴于您发布的 s3.yml,我认为 s3_credentials 不会像生产环境中那样填充 json 结构。

我建议您像在生产环境中一样加载文件并填充 json。

【讨论】:

  • 我认为这是问题所在,但是当我将其更改为生产中的内容时,我得到了 `fetch': key not found: “S3_BUCKET_NAME”。
  • 我想通了!非常感谢您为我指明了正确的方向! :)) 我需要通过执行以下操作将值添加到终端中的 ENV 变量:export ENV_VARIABLE_NAME="value"
猜你喜欢
  • 1970-01-01
  • 2012-04-25
  • 2012-05-02
  • 1970-01-01
  • 1970-01-01
  • 2016-06-01
  • 2016-10-01
  • 1970-01-01
  • 2020-02-24
相关资源
最近更新 更多