首页 > 解决方案 > 如何从 amazon cognito 提供的凭证访问 S3 存储桶?

问题描述

我正在使用 amazon s3 存储桶上传我的图片。我收到了来自 google 的警告邮件,说我的 AWS 凭证已暴露。所以现在我正在替换代码并使用 amazon cognito。

我无法访问存储桶。该错误表示访问被拒绝。

这是我的代码:

 credentialsProvider = new CognitoCachingCredentialsProvider(
            context, // get the context for the current activity
            "xxxxxxx", // your AWS Account id
            "ap-southeast-1:3d4e113d-4cd3-47ac-b5ef-xxxxxxxxxx", // your identity pool id
            "arn:aws:iam::xxxxxxxxx:role/Cognito_trackusersUnauth_Role",// an authenticated role ARN
            "arn:aws:iam::xxxxxxxxx:role/Cognito_trackusersAuth_Role", // an unauthenticated role ARN
            Regions.AP_SOUTHEAST_1 //Region
    );


    s3 = new AmazonS3Client(credentialsProvider);
    s3.setEndpoint("s3-ap-southeast-1.amazonaws.com");

这是它说访问被拒绝的地方:

 List<Bucket> buckets = s3.listBuckets();

标签: androidamazon-web-servicesamazon-s3amazon-cognito

解决方案


推荐阅读