由于获取了公开可用的S3对象而拒绝访问

时间:2019-04-02 11:17:42

标签: amazon-web-services amazon-s3 aws-sdk-net

我创建了一个存储桶,在该存储桶中可以公开访问对象。 我将文件放在该存储桶中,并且可以通过简单的HTTP GET请求(甚至从匿名浏览器访问)访问文件。 但是,尝试使用适用于.net的AWS开发工具包的.NET的GetObject函数(甚至使用AWS CLI)访问相同的文件时,出现访问被拒绝错误。 我可能做错了什么?

Private region As RegionEndpoint = RegionEndpoint.EUCentral1

Public Function ReadObject(ByVal bucket As String, ByVal key As String) As String
  Dim request As New GetObjectRequest()
  request.BucketName = bucket
  request.Key = key
  Dim responseBody As String
  Dim client As New AmazonS3Client(region)
  Using response As GetObjectResponse = client.GetObject(request)
    Using responseStream As Stream = response.ResponseStream
      Using reader As New StreamReader(responseStream)
        responseBody = reader.ReadToEnd()
      End Using
    End Using
  End Using
  Return responseBody
End Function

0 个答案:

没有答案