AWS无法订阅SNS主题:CognitoIdentityCredentials未被授权执行:SNS:Subscribe。

4
我正在尝试使用以下代码将iOS端点订阅到SNS主题:

我正在尝试使用以下代码将iOS端点订阅到SNS主题:

    let sns = AWSSNS.defaultSNS()
    let request = AWSSNSCreatePlatformEndpointInput()
    request.token = deviceTokenString
    request.platformApplicationArn = SNSPlatformApplicationArn

    sns.createPlatformEndpoint(request).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task: AWSTask!) -> AnyObject! in
        if task.error != nil {
            print(task.error)
        } else {
            let createEndpointResponse = task.result as! AWSSNSCreateEndpointResponse

            // Subscribe to the topic
            let subscribeTopicInput = AWSSNSSubscribeInput()
            subscribeTopicInput.endpoint = createEndpointResponse.endpointArn
            subscribeTopicInput.protocols = "application"
            subscribeTopicInput.topicArn = MyTopicARN
            sns.subscribe(subscribeTopicInput).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (topicTask: AWSTask!) -> AnyObject! in

                if topicTask.error != nil {
                    // Authorization error prints here
                    print(topicTask.error)
                }

                return nil
            })

        }

        return nil
    })

我在尝试订阅主题时收到错误:

UserInfo={Type=Sender, Message=User: arn:aws:its::000000000000:assumed-role/appname_unauth_MOBILEHUB_000000000/CognitoIdentityCredentials is not authorized to perform: SNS:Subscribe on resource:...

这个答案的作者解释说,您必须在Cognito角色中授予对sns:Subscribe的访问权限,以允许应用程序进行此调用。我的Cognito用户已被授予AmazonSNSFullAccess,它允许访问所有sns操作(例如sns:*)。为什么我的Cognito用户被拒绝访问?我的主题策略设置为只有主题所有者可以订阅…但主题所有者似乎与我的Cognito用户相同。

enter image description here

1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
2
我曾使用亚马逊移动中心为我配置推送通知,但我没有意识到移动中心在此过程中会创建三个角色:
  1. appname_consolepush_MOBILEHUB_000000000
  2. appname_unauth_MOBILEHUB_000000000
  3. MobileHub_Service_Role
iOS应用程序是使用 appname_unauth_MOBILEHUB_00000000 角色连接的,而不是我手动创建的用户。该角色不允许 sns:Subscribe。 要解决这个问题,可以选择以下其中一种方式:
  1. AmazonSNSFullAccess 授予适当的角色
  2. 创建内联策略以允许所有资源进行 sns:Subscribe(在我看来更好)
例如:
{
    "Effect": "Allow",
    "Action": [
        "sns:Subscribe"
    ],
    "Resource": [
        "*"
    ]
}

很高兴听到你让它工作了。如果您有任何问题,请随时在此处或我们的论坛中发帖。 - Rachit Dhall
1
另外请注意:您不能仅复制/粘贴上面的内容,这将失败验证。也不应该给予完全访问权限。完成此操作最简单的方法是使用策略生成器并选择SNS和Subscribe。超级简单。 - user3344977

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,