func setupCredentialsProvIDer() { let credentialsProvIDer = AWSCognitoCredentialsProvIDer(regionType:.USEast1,IDentityPoolID:IDentityPoolIDStr) let configuration = AWSServiceConfiguration(region:.USEast1,credentialsProvIDer:credentialsProvIDer) AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration AWSServiceConfiguration(region: AWSRegionType.USEast1,credentialsProvIDer: credentialsProvIDer)}func ListObjects() { let s3 = AWSS3.defaultS3() let ListObjectsRequest = AWSS3ListObjectsRequest() ListObjectsRequest.bucket = S3Bucketname s3.ListObjects(ListObjectsRequest).continueWithBlock { (task) -> AnyObject! in if let error = task.error { print("ListObjects Failed: [\(error)]") } if let exception = task.exception { print("ListObjects Failed: [\(exception)]") }}
当我运行应用程序并调用ListObjects()时,我收到此错误:
ListObjects Failed: [Error Domain=com.amazonaws.AWSServiceErrorDomain Code=11 “(null)” UserInfo={HostID=,Message=Access DenIEd,Code=AccessDenIEd,RequestID=}]
我错过了什么?
解决方法 如果它与我遇到的问题类似,那么经过身份验证的Cognito用户无权访问特定的S3存储桶.阅读 Understanding Amazon Cognito Authentication Part 3: Roles and Policies给了我所需的线索,具体来说:When you create your IDentity pool via the Cognito console,it will create two roles for you,one for authenticated users and one for unauthenticated users,but you can visit the IAM Console and create more roles than just these. You can also modify the existing roles to add support for additional services such as Amazon S3 or Amazon DynamoDB,depending on your use case.
所以我决定为经过身份验证的用户修改创建的角色,以允许访问我的S3存储桶:
>切换到您的IAM控制台并找到一个名为的角色:
xxxx_auth_yyy – auth子串是其中的重要部分
将角色标识为经过身份验证的用户的角色.
>使用此角色通过以下方式为经过身份验证的用户分配权限
>创建策略(策略 – >创建策略)以提供特定存储桶所需的访问权限.
>将此政策“附加”到经过身份验证的角色(角色 – > xxxx_auth_yyy – >附加政策).
>您的代码现在应该能够列出特定S3存储桶中的文件.
示例策略(步骤3):
{ "Version": "2012-10-17","Statement": [ { "Effect": "Allow","Action": [ "s3:ListBucket","s3:Getobject","s3:PutObject" ],"Resource": [ "arn:aws:s3:::BUCKET_name*" ] } ]}总结
以上是内存溢出为你收集整理的适用于iOS的AWS开发工具包:无法列出S3存储桶中的文件全部内容,希望文章能够帮你解决适用于iOS的AWS开发工具包:无法列出S3存储桶中的文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)