我创建了一个IAM策略,允许Cognito用户写入我的S3存储桶,但我想根据他们的Cognito ID将它们限制为文件夹.我在这里遵循亚马逊的指示并创建了一个如下所示的策略:
{
"Effect": "Allow",
"Action": ["s3:PutObject","s3:GetObject"],
"Resource": [
"arn:aws:s3:::mybucket/myappfolder/${cognito-identity.amazonaws.com:sub}*"
]
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用AWS iOS SDK的v2上传时,我收到了拒绝访问错误.
如果我修改资源的最后一个路径组件以替换我从SDK获得${cognito-identity.amazonaws.com:sub}的显式identityId值,AWSCognitoCredentialsProvider它可以工作.
{
"Effect": "Allow",
"Action": ["s3:PutObject","s3:GetObject"],
"Resource": [
"arn:aws:s3:::mybucket/myappfolder/us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx*"
]
}
Run Code Online (Sandbox Code Playgroud)
我的理解是,这些应该等同于同一件事.我在政策中遗漏了什么,或者我应该在上传请求中使用不同的路径?
**更新**
我最初在iOS中遇到过这个问题,所以今晚我尝试在node.js中做同样的事情,结果是一样的.这是我在节点中使用的简单代码:
var s3 = new AWS.S3();
AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials(AWSParams);
AWS.config.credentials.get(function (err) {
if (!err) {
console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);
var bucketName = 'ch123_test_bucket';
var keyName = AWS.config.credentials.identityId + '.txt';
var params = {Bucket: bucketName, Key: keyName, …Run Code Online (Sandbox Code Playgroud) 我有一个使用MultiPeer连接框架的应用程序.每次应用程序在AppDelegate中变为活动状态时,我都会创建一个新的MCSession,一个MCNearbyBrowserService和一个MCNearbyAdvertiserService并调用开始浏览并开始广告.然后,每次应用程序在AppDelegate中变为非活动状态时,我都会停止浏览和广告并将所有内容设置为零.我发现MCNearbyBrowserService导致其syncQueue崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** - [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
*** First throw call stack:
(0x2de3ee8b 0x381396c7 0x2dd7caef 0x2dd7c8b3 0x2f648167 0x2f6493af 0x3861e103 0x38622e77 0x3861ff9b 0x38623751 0x386239d1 0x3874ddff 0x3874dcc4)
libc++abi.dylib: terminating with uncaught exception of type NSException
Run Code Online (Sandbox Code Playgroud)
有时当应用程序重新打开时.
这是applicationDidBecomeActive的代码:
self.myIdentifier = [[MCPeerID alloc] initWithDisplayName:[self.class createHash:20]];
self.mainSession = [[MCSession alloc] initWithPeer:self.myIdentifier];
self.mainSession.delegate = self;
peerAdvertiser = [[MCNearbyServiceAdvertiser alloc] initWithPeer:self.myIdentifier discoveryInfo:nil serviceType: service];
peerAdvertiser.delegate = self;
peerBrowser = [[MCNearbyServiceBrowser alloc] initWithPeer:self.myIdentifier serviceType: …Run Code Online (Sandbox Code Playgroud)