17

我原本以为这个问题是由于区域不匹配造成的,但是在更改区域后,我在尝试此处找到的 Amazon AWS 示例时仍然遇到以下错误:

DynamoDBMapper

 AmazonServiceException: User: arn:aws:sts::[My Account
 ARN]:assumed-role/Cognito_AndroidAppUnauth_DefaultRole/ProviderSession
 is not authorized to perform: dynamodb:DescribeTable on resource:
 arn:aws:dynamodb:us-east-1:[My Account ARN]:table/test_table (Service:
 AmazonDynamoDBv2; Status Code: 400; Error Code: AccessDeniedException;
 Request ID: BBFTS0Q8UHTMG120IORC2KSASVVV4KQNSO5AEMVJF66Q9ASUAAJG)

一切都或多或少相同,我唯一更改的是将DBclient区域更改US_EAST_1为托管我的测试表的区域,并使用通过以下生成的“Amazon Cognito Starter Code”页面中的信息修改常量文件Cognito 入门文档。

sdkforandroid-cognito-auth

对于我的Cognito_AndroidAppUnauth_DefaultRole角色策略,我修改了默认的移动分析和同步服务权限,以包括对所有表的所有操作的访问,无论是否存在:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "CognitoPolicy",
            "Action": [
                "mobileanalytics:PutEvents",
                "cognito-sync:*"
            ],
            "Effect": "Allow",
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "DynamoDBPolicy",
            "Effect": "Allow",
            "Action": [
                "dynamodb: *"
            ],
            "Resource": "*"
        }
    ]
}

那么为什么在使用正确的区域并且 Unauth 策略应该允许表访问时声称它没有权限呢?

编辑:调用 DynamoDB 资源(创建表)上的方法时的 Stacktrace,它是否有用

   com.amazonaws.AmazonServiceException: User: arn:aws:sts::[My Account ARN]:assumed-role/Cognito_AndroidAppUnauth_DefaultRole/ProviderSession is not authorized to perform: dynamodb:CreateTable on resource: arn:aws:dynamodb:us-east-1:[My Account ARN]:table/test_table (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: AccessDeniedException; Request ID: SDELNSMLO10EV7CM2STC1R9RU3VV4KQNSO5AEMVJF66Q9ASUAAJG)
            at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(Unknown Source)
            at com.amazonaws.http.AmazonHttpClient.executeHelper(Unknown Source)
            at com.amazonaws.http.AmazonHttpClient.execute(Unknown Source)
            at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(Unknown Source)
            at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.createTable(Unknown Source)
            at com.amazonaws.demo.userpreferencesom.DynamoDBManager.createTable(DynamoDBManager.java:72)
            at com.amazonaws.demo.userpreferencesom.UserPreferenceDemoActivity$DynamoDBManagerTask.doInBackground(UserPreferenceDemoActivity.java:99)
            at com.amazonaws.demo.userpreferencesom.UserPreferenceDemoActivity$DynamoDBManagerTask.doInBackground(UserPreferenceDemoActivity.java:85)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
4

3 回答 3

23

与亚马逊工程师合作,结果发现问题出在策略配置中:

"dynamodb: *"

应该

"dynamodb:*"

一个空间能做什么真是太神奇了。

于 2014-07-15T21:01:40.387 回答
0

就我而言,我的表名包含一个无效的“/”字符。从表名中删除“/”字符解决了这个问题。

于 2020-05-20T08:31:10.667 回答
-1

您可以改为将权限分配给 lambda 的角色,如下所示:

在此处输入图像描述

于 2020-07-06T22:31:49.480 回答