【问题标题】:accessing aws private bucket in android without cognito在没有 cognito 的情况下访问 android 中的 aws 私有存储桶
【发布时间】:2020-12-11 22:53:30
【问题描述】:

我是使用 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, read, delete`

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

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

【问题讨论】:

    标签: android amazon-web-services amazon-s3 aws-amplify aws-amplify-sdk-android


    【解决方案1】:

    目前,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 中使用的。

    【讨论】:

      【解决方案2】:

      如果用户应该能够在无需身份验证的情况下访问存储桶,您可以使该存储桶中的对象可公开访问。这样,您就可以跳过访问私有存储桶所涉及的额外工作,以便轻松访问您想要轻松访问的对象(无需身份验证)。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-16
        • 2020-02-29
        • 2018-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-12
        • 2019-01-25
        相关资源
        最近更新 更多