我正在尝试将 S3 和 Cognito 集成到我的 iOS 应用程序中,到目前为止还没有成功。我相信该错误与我的 IAM Auth 和 Unauth 用户政策有关。所以这是我的政策:
{
"Version": "2012-10-17",
"Statement":
[{
"Effect":"Allow",
"Action":"cognito-sync:*",
"Resource":["arn:aws:cognito-sync:us-east-1:XXXXXXXXXXXX:identitypool/${cognito-identity.amazonaws.com:aud}/identity/${cognito-identity.amazonaws.com:sub}/*"]
},
{
"Effect":"Allow",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::my_bucket",
"arn:aws:s3:::my_bucket/*"]
}
]
}
这是我称之为 S3 的地方:
AWSS3GetObjectRequest *getObjectRequest = [[AWSS3GetObjectRequest alloc] init];
getObjectRequest.key = KEY;
getObjectRequest.bucket = BUCKET;
//default service has been configured previously
AWSS3 *s3 = [[AWSS3 new] initWithConfiguration:[AWSServiceManager defaultServiceManager].defaultServiceConfiguration];
[[s3 getObject:getObjectRequest] continueWithBlock:^id(BFTask *task) {
if(task.error)
{
NSLog(@"Error: %@",task.error);
}
else
{
NSLog(@"Got File");
NSData *data = [task.result body];
NSString *urlString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}
return nil;
}];
这是错误:
错误:错误域 = com.amazonaws.AWSSTSErrorDomain 代码 = 0“AccessDenied -- 无权执行 sts:AssumeRoleWithWebIdentity” UserInfo=0x10a23e0a0 {NSLocalizedDescription=AccessDenied -- 无权执行 sts:AssumeRoleWithWebIdentity}
那么,我做错了什么?