繁体   English   中英

重新归档和“ aws-sdk” V2 gem丢失区域错误

[英]Refile and 'aws-sdk' V2 gem getting Missing Region Error

我正在使用最新版本的refile gem将图像上传到AWS,并且工作正常。 当我尝试使用rspec测试我的应用程序时,出现以下错误:

/aws-sdk-core/plugins/regional_endpoint.rb:34:in after_initialize中:缺少区域; 使用:region选项或将区域名称导出到ENV ['AWS_REGION'](Aws :: Errors :: MissingRegionError)

宝石文件:

gem“ refile”,要求:“ refile / rails”

宝石“ refile-mini_magick”

宝石“ refile-s3”

refile.rb

需要'refile / simple_form'

需要“ refile / s3”

aws = {

access_key_id:ENV ['AWS_ACCESS_KEY_ID'],

secret_access_key:ENV ['AWS_SECRET_ACCESS_KEY'],

区域:ENV ['AWS_REGION'],

值区:ENV ['AWS_BUCKET']

}

Refile.cache = Refile :: S3.new(前缀:“缓存”,** aws)

Refile.store = Refile :: S3.new(前缀:“ store”,** aws)

我尝试设置一个新的初始化器aws.rb

需要'aws-sdk'

Aws.config.update({地区:'us-west-2',凭据:Aws :: Credentials.new('akid','secret')})

但它没有用。

10倍的帮助!

看起来您的代码正在寻找AWS_REGION值作为环境变量。 在运行测试之前,您是否已验证在环境中设置了AWS_REGION的值? 您可以通过执行以下操作查看它是否设置在bash中:

env | grep AWS_REGION

如果未设置,则只需像这样设置变量(再次在bash中):

export AWS_REGION="us-west-2"

找到了答案:只需添加到您的initializers / refile.rb中:

require "refile/s3"
require 'refile/simple_form'

if Rails.env.production?
  aws = {
    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    region: ENV['AWS_REGION'],
    bucket: ENV['AWS_BUCKET']
  }

  Refile.cache = Refile::S3.new(prefix: "cache", **aws)
  Refile.store = Refile::S3.new(prefix: "store", **aws)
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM