我已經使用 Amplify、CLI 控制臺在 Amazon AWS 上設定了一個存盤桶。我遵循了 Amplify iOS SDK 的檔案,并在 iOS 應用程式上安裝了以下設定代碼:
do {
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.add(plugin: AWSS3StoragePlugin())
try Amplify.configure()
} catch {
print(message: "An error occurred setting up Amplify: \(error)")
}
當我嘗試下載資源時,出現以下錯誤:
StorageError: The HTTP response status code is [403].
我正在使用以下代碼:
var url: URL = //url to download to
var key: String = //key for the file as specified in S3
operation = Amplify.Storage.downloadFile(key: key,
local: url) { [weak self] progress in
guard let _ = self else { return }
print(message: "progress: \(progress.fractionCompleted)")
} resultListener: { [weak self] result in
guard let _ = self else { return }
switch result {
case .success:
print(message: "success!")
case .failure(let error):
print(message: "error: \(error)")
}
}
用戶通過我建立了amplify configure具有AdministratorAccess和AmazonS3ReadOnlyAccess附加政策:

我錯過了什么?
uj5u.com熱心網友回復:
用戶創建的通過amplify configure是使用中擴增的資源調配-您分配AdministratorAccess和AmazonS3ReadOnlyAccess政策,以你的用戶中擴增但不與未認證用戶的作用,而這一點正是使用中擴增guest用戶。
首先找到未經身份驗證的角色的角色名稱,登錄
用于訪客/未經身份驗證的用戶的當前角色將在下拉串列中。
在 IAM 控制臺中查找角色名稱,然后將 AWS 管理的AmazonS3ReadOnlyAccess策略附加到角色。
您的未經身份驗證的用戶現在應該有權從 S3 存盤桶讀取檔案,您應該不會再收到403 Access Denied錯誤訊息。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/322511.html
