我正在按照AWS的官方教程从S3存储桶下载图像。在IAM控制台中,我创建了一个新用户,该用户具有对存储桶的只读访问权限。在将证书添加到.aws文件夹中并使用放大CLI后,创建了新的Cognito用户池,Cognito身份池和S3存储桶。
我已经在Swift应用程序中安装了Amplify,AmplifyPlugins / AWSS3StoragePlugin,AmplifyPlugins / AWSCognitoAuthPlugin吊舱。在调用amplify push之后,已使用凭据更新了amplifyconfiguration.json和awsconfiguration.json。
在AppDelegate中,我设置了以下演示代码:
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)")
}
})
}
问题是我收到故障:
authError:
0:字符串“没有用户登录来获取身份ID”
1:字符串“调用Auth.signIn来登录用户或在AWS Cognito身份池中启用未经身份验证的访问”
使用AWS的最新放大SDK并以只读权限安全连接S3的最佳步骤是什么?理想情况下,我想使用我创建的现有存储桶而不是生成的现有存储桶。
withAuthenticator
component进行身份验证,而不是通过未经身份验证的用户使用。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句