阅读背景:

Seahorse :: Client :: NetworkingError(主机名“mybucketname.s3.s3-us-west-2.amazonaws.com”与服务器证书不匹配)

来源:互联网 

I'm having an issue with calling .head_object using Amazon AWS SDK Version 2. I'm working in a Rails project, using Figaro to set my environment variables and have named them as AWS SDK expects: AWS_ACCESS_KEY_ID, etc.

我在使用Amazon AWS SDK Version 2调用.head_object时遇到问题。我正在使用Figaro工作,使用Figaro设置我的环境变量并将其命名为AWS SDK期望:AWS_ACCESS_KEY_ID等。

Here's the code I'm using to try to call head_object:

这是我用来尝试调用head_object的代码:

direct_upload_url_data = %r{\/(?<path>uploads\/.+\/(?<filename>.+))\z}.match(direct_upload_url)
direct_upload_url_data_string = direct_upload_url_data.to_s
s3 = Aws::S3::Client.new
direct_upload_head = s3.head_object(
    bucket: ENV['AWS_BUCKET'],
    key: direct_upload_url_data_string
  )

  self.image_file_name     = direct_upload_url_data[:filename]
  self.image_file_size     = direct_upload_head.content_length
  self.image_content_type  = direct_upload_head.content_type
  self.image_updated_at    = direct_upload_head.last_modified

As you can see I'm trying to access a specific file's metadata. I've checked the regex and it seems to be returning the correct key which is something like "uploads/{uniqueID}/image.jpg" The error is coming on the line where I am trying to call head_object. The error I'm getting is

如您所见,我正在尝试访问特定文件的元数据。我已经检查了正则表达式,它似乎正在返回正确的键,就像“uploads / {uniqueID} /image.jpg”这个错误正在我想要调用head_object的行上。我得到的错误是

Seahorse::Client::NetworkingError (hostname "mybucketname.s3.s3-us-west-2.amazonaws.com" does not match the server certificate)

That path is not what I see when I go to my bucket, I see https://s3-us-west-2.amazonaws.com/mybucketname so I'm not sure if that's the reason I'm getting the error. I've connected to this bucket before using AWS SDK Version 1 so I know my access and secret keys are working fine. Thanks in advance for your help.

当我去我的桶时,这条路不是我看到的,我看到https://s3-us-west-2.amazonaws.com/mybucketname所以我不确定这是否是我收到错误的原因。在使用AWS SDK Version 1之前,我已连接到此存储桶,因此我知道我的访问权限和密钥正常工作。在此先感谢您的帮助。

2 个解决方案

#1


0  

It seems like you have a wrong region name for your amazon bucket. Try to change "s3-us-west-2" to "us-west-2".

您的亚马逊水桶似乎有错误的地区名称。尝试将“s3-us-west-2”改为“us-west-2”。

#2


0  

I'm very sure you've already resolved the issue but for future readers, as tapatun mentioned, make sure your region name does not include the s3 prefix and should read: "us-west-2".

我非常肯定你已经解决了这个问题但是对于未来的读者来说,正如tapatun所提到的,请确保你的地区名称不包含s3前缀,并且应该是:“us-west-2”。

But afterwards, make sure to restart your server, otherwise the old configurations may still remain making you go on a wild goose chase!

但之后,请确保重新启动服务器,否则旧的配置可能仍会让您继续疯狂追逐!

Good luck and happy coding everyone!

祝大家好运!


分享到: