我正在尝试访问Bucket并从S3上传/下载文件,我不断收到以下异常:
引起:javax.net.ssl.SSLPeerUnverifiedException:主机名' s3.eu-west-1.amazonaws.com'与对等方提供的证书主题不匹配(CN = * .s3-eu-west-1.amazonaws.com,O = Amazon.com Inc.,L = Seattle,ST = Washington,C = US)
这是我的代码(它是scala,但可以翻译成Java):
val bucket = config.getString("aws.bucket").getOrElse("none")
val accessKey = config.getString("aws.accessKeyId").getOrElse("none")
val secretKey = config.getString("aws.secretKey").getOrElse("none")
val region = config.getString("aws.region").getOrElse("none")
val credentials = new BasicAWSCredentials(accessKey, secretKey)
val s3 = new AmazonS3Client(credentials)
s3.setRegion(new com.amazonaws.regions.Region(new InMemoryRegionImpl(region, null)))
val s3Obj = s3.putObject(new PutObjectRequest(bucket, "test1.jpg", new File("/Users/test/Desktop/nature.jpg")))
更多信息:我使用的是最新版本的Java SDK,我使用的是V4。
答案 0 :(得分:0)
看起来SSL证书期望主机名中还有一个级别,例如
myhost.s3-eu-west-1.amazonaws.com
^^^^^^^
其中myhost
是您的桶名称。