Reputation: 13444
I want to upload a file to one of my S3 buckets.
In my app I have:
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "us-east-1:05da3124-9aab-abd9-081231a31")
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
func uploadFile(fileURL: NSURL, type: MediaType) {
var uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.body = fileURL
uploadRequest.key = fileURL.lastPathComponent
uploadRequest.bucket = "xxx.xxx.dev"
transferManager.upload(uploadRequest).continueWithBlock { (task) -> AnyObject! in
if let error = task.error {
log.debug("Upload failed with error: \(error)")
} else {
log.debug("Object \(uploadRequest.key) uploaded with \(task.result)")
XXXRESTManager.sharedInstance.doRegisterUpload(uploadRequest.key, type: type)
}
return nil
}
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3: PutObject"
],
"Resource": "arn:aws:s3:::xxx.xxx.dev"
},
{
"Effect": "Allow",
"Action": [
"sns:CreatePlatformEndpoint",
"sns:Subscribe"
],
"Resource": [
"*"
]
}
]
}
The connection to cognito is correct (i now have one unauthenticated user in AWS console.
However I still get a permission denied when I try to upload a file. What did I missed?
Upvotes: 2
Views: 376
Reputation: 13444
I don't know what caused the issue, but I managed to make it work. The code in the question IS correct.
Upvotes: 0
Reputation: 683
AWSS3TransferManagerUploadRequest
might need more permissions than just PutObject to work. Have you tried giving broader permissions for S3 on your policy? Probably it needs at least GetObject, but try first with "Action": "s3:*"
so we can make sure the problem is in that part.
Upvotes: 1