I am following the official tutorial from aws to download images from an S3 Bucket. In the IAM console I have created a new user that has read only access to the bucket. After adding the credential in the .aws folder and using the amplify CLI new Cognito User Pool, Cognito Identity Pool and S3 buckets were created.
I have installed the Amplify, AmplifyPlugins/AWSS3StoragePlugin, AmplifyPlugins/AWSCognitoAuthPlugin pods in the Swift app. The amplifyconfiguration.json and awsconfiguration.json have been updated with credentials after calling amplify push.
In the AppDelegate I have set the following demo code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
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)")
}
self.testUploadData()
return true
}
func testUploadData() {
let dataString = "Example file contents"
let data = dataString.data(using: .utf8)!
Amplify.Storage.uploadData(key: "ExampleKey", data: data,
progressListener: { progress in
print("Progress: \(progress)")
}, resultListener: { (event) in
switch event {
case .success(let data):
print("Completed: \(data)")
case .failure(let storageError):
print("Failed: \(storageError.errorDescription). \(storageError.recoverySuggestion)")
}
})
}
The problem is that I am receiving the failure:
authError:
0: String "There is no user signed in to retreive identity id"
1: String "Call Auth.signIn to sign in a user or enable unauthenticated access in AWS Cognito Identity Pool"
What are the best steps to use the latest amplify SDK from AWS and also securely connecting on S3 with read-only permissions? Ideally I would like to use and existing bucket I have created instead of the generated one.
withAuthenticator
component.