我已经创建了UserPool和身份池,并成功执行了Signup和SignIn。但是,当我尝试访问S3上载图像时,出现以下错误。
错误: com.amazonaws.services.s3.model.AmazonS3Exception:访问被拒绝(服务:null;状态代码:403;错误代码:AccessDenied;
这是导致错误的代码段。
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"MY_Identity_Pool_ID", // Identity pool ID
Regions.MY_Region// Region
);
TransferUtility transferUtility =
TransferUtility.builder()
.context(getApplicationContext())
.awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
.s3Client(new AmazonS3Client(credentialsProvider, Region.getRegion(Regions.AP_SOUTH_1)))
.build();
Log.d("imagepath", images.get(0).getPath());
TransferObserver uploadObserver =
transferUtility.upload(
"apples.jpeg",
new File(images.get(0).getPath()));
答案 0 :(得分:0)
我通过为IAM中的授权角色提供S3访问策略来解决此问题。