【问题标题】:Refile returning Aws::S3::Errors::Forbidden: error重新文件返回 Aws::S3::Errors::Forbidden: 错误
【发布时间】:2026-02-21 03:15:01
【问题描述】:

突然Refile gem 在尝试从 S3 存储桶中获取图像时开始抛出 Aws::S3::Errors::Forbidden: 错误。尽管我能够上传/获取新图像,但此问题仅适用于旧文件。

我尝试向 S3 添加新的存储桶策略,如此处所述:https://github.com/aws/aws-sdk-ruby/issues/201 但似乎没有一个对我有用,可能是我写的不正确。

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Principal": "*",
        "Action": "s3:*",
        "Resource": [
            "arn:aws:s3:::bucket/*",
            "arn:aws:s3:::bucket"
        ]
    }
]
}

以下是错误日志:

Aws::S3::Errors::Forbidden:
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/gems/aws-sdk-resources-2.6.4/lib/aws-sdk-resources/resource.rb:134:in `rescue in exists?'
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/gems/aws-sdk-resources-2.6.4/lib/aws-sdk-resources/resource.rb:131:in `exists?'
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/gems/refile-s3-0.2.0/lib/refile/s3.rb:126:in `exists?'
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/bundler/gems/refile-d7a42dcd7cf6/lib/refile/backend_macros.rb:11:in `block (2 levels) in verify_id'
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/bundler/gems/refile-d7a42dcd7cf6/lib/refile/file.rb:53:in `exists?'
from (irb):3
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/deploy/hutfy/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'

【问题讨论】:

    标签: ruby-on-rails amazon-web-services amazon-s3 refile


    【解决方案1】:

    事实证明服务器和 S3 上的时钟不同步。 运行下面的命令解决了这个问题:

    sudo apt-get install ntp
    service ntp stop
    sudo ntpdate -s 0.amazon.pool.ntp.org
    service ntp start
    

    【讨论】:

    • 你到底是怎么发现这个的?!你让我开心,谢谢!
    • @GuneyCobanoglu 我查找了相关错误,因为我在谷歌搜索时找不到任何具有确切错误的内容,我想我很幸运。