[英]Seahorse::Client::NetworkingError (hostname “mybucketname.s3.s3-us-west-2.amazonaws.com” does not match the server certificate)
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开发工具包版本2调用.head_object时遇到问题。我正在Rails项目中工作,使用Figaro设置环境变量并将其命名为AWS开发工具包期望的名称: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. 我检查了正则表达式,它似乎返回了正确的密钥,类似于“ uploads / {uniqueID} /image.jpg”之类的错误。我试图调用head_object的那一行出现了错误。 The error I'm getting is 我得到的错误是
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. 当我进入存储桶时,该路径不是我看到的,我看到的是https://s3-us-west-2.amazonaws.com/mybucketname,因此我不确定这是否是我得到错误的原因。 I've connected to this bucket before using AWS SDK Version 1 so I know my access and secret keys are working fine. 在使用AWS开发工具包版本1之前,我已连接到此存储桶,因此我知道我的访问和密钥工作正常。 Thanks in advance for your help. 在此先感谢您的帮助。
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”。
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! 祝大家好运,祝大家编码愉快!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.