在没有认知的情况下访问android中的AWS私有存储区

问题描述

我对使用AWS不熟悉,遇到了一些麻烦。我在aws s3 bucket的多个文件夹中都有一组视频。我正在创建一个Android应用,它将读取存储桶的视频,将其显示为列表,并允许用户流式传输这些视频。

问题是我的应用程序使用非AWS单独的服务器进行身份验证,因此我不想使用aws-cognito身份验证。当我尝试为s3搜索本机sdk时,我被指向aws-amplify框架,而当我尝试遵循文档here时,我被困在该step上,它强制设置认知身份验证。

? You need to add auth (Amazon Cognito) to your project in order to add storage for user files. Do you want to add auth Now?
    `Yes` // <------------------------ this is for either Now or later,can't say no to adding auth at all   

? Do you want to use the default authentication and security configuration?
    `Default configuration` //<-------------------------------------- can't say no here

? How do you want users to be able to sign in?
    `Username`

? Do you want to configure advanced settings?
    `No,I am done.`

? Please provide a friendly name for your resource that will be used to label this category in the project:
    `S3friendlyName`

? Please provide bucket name:
    `storagebucketname`

? Who should have access:
    `Auth and guest users`

? What kind of access do you want for Authenticated users?
    `create/update,read,delete`

? What kind of access do you want for Guest users?
    `create/update,delete`

? Do you want to add a Lambda Trigger for your S3 Bucket?
    `No`

对此我不确定,但是我相信有一种方法可以仅使用iam用户访问键来访问某些私有存储区数据。那么,哪种sdk或自定义代码可以帮助我无需验证就可以访问所有用户的整个私有存储桶?

解决方法

如果假定用户无需身份验证即可访问存储桶,则可以使该存储桶中的对象可公开访问。这样一来,您就无需为访问打算轻松访问(无需身份验证)的对象访问私有存储桶所涉及的额外工作。

如果存储桶中的对象和存储桶本身必须保持私有,则可以按照this guide: "Restricting Access to Amazon S3 Content by Using an Origin Access Identity来控制通过CloudFront对S3的访问。从理论上讲,除非来自OAI配置的CloudFront发行版,否则用户将无法访问您的S3内容。然后,您可以找到一种方法,仅使用应用程序访问CloudFront分发并从那里获取内容。

,

当前,Amplify的AWSS3StoragePlugin被硬编码为要求使用Amazon Cognito进行身份验证/授权。

如果您只想使用IAM ,请在Amplify Android GitHub存储库上create a feature request

如果您想使用自己的凭据提供程序进行身份验证,则可以federated an OpenID Connect provider with Cognito

核选项将使用the low-level AmazonS3Client,in the AWS SDK for Android。这将允许您提供自己的AWSCredentialsProvider。有a variety of valid ways to provide credentials。注意:AWSMobileClient是用于执行Cognito身份验证的实用程序,它是AWSS3StoragePlugin中使用的工具。