I am trying to download an object from existing s3 bucket to IOS app using amplify-swift. I've followed the tutorial to init amplify, and import storage. I am trying to do a call for an unauthenticated user-> In Cognito console I defined a role for unauth user, (and allowed access to unauth users), gave him permissions to my bucket and verified with simulator that getObject works. When calling this code:
let key = "images/some_file.txt"
do {
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.add(plugin: AWSS3StoragePlugin())
try Amplify.configure()
print("Amplify configured with storage plugin")
} catch {
print("Failed to initialize Amplify with \(error)")
}
Amplify.Storage.downloadData(
key: key,
progressListener: { progress in
print("Progress: \(progress)")
}, resultListener: { (event) in
switch event {
case let .success(data):
print("Completed: \(data)")
case let .failure(storageError):
print("Failed: \(storageError.errorDescription). \(storageError.recoverySuggestion)")
}
})
I get this error:
Amplify configured with storage plugin 2021-03-31 18:09:09.988304+0300 ota[30840:728969] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed Progress: <NSProgress: 0x6000001d50e0> : Parent: 0x0 (portion: 0) / Fraction completed: 0.0000 / Completed: 243 of -1
Failed: The HTTP response status code is [403].. TODO some status code to recovery message mapper. For more information on HTTP status codes, take a look at https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
I checked that the pool id, bucket name are all defined correctly in the json files. What am I missing?
EDIT:
this seems to work, so i know the actual problem is not with the permissions, but rather with the amplify default download:
let expression = AWSS3TransferUtilityDownloadExpression()
expression.progressBlock = {(task, progress) in DispatchQueue.main.async(execute: {
print("Downloading...")
})
}
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .EUWest1, identityPoolId: "eu-west-1:xxxxxx")
let configuration = AWSServiceConfiguration(region: .EUWest1, credentialsProvider: credentialProvider)
AWSS3TransferUtility.register(with: configuration!, forKey: "customTU")
let tu = AWSS3TransferUtility.s3TransferUtility(forKey: "customTU")
tu?.downloadData(fromBucket: bucket, key: _key, expression: expression) { (task, URL, data, error) in
if error != nil {
print(error!)
}
DispatchQueue.main.async(execute: {
print("Got here")
let rawJSON = (String(data: data!, encoding: .utf8))!
print(rawJSON)
})
}