我在尝试使用此代码认购在iOS终端的SNS话题:AWS无法订阅SNS主题:CognitoIdentityCredentials无权执行: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:...
的this answer笔者解释说,您必须授予在Cognito角色访问sns:Subscribe
,让您的应用程序,使这个电话。我的Cognito用户已被授予AmazonSNSFullAccess
,允许访问所有sns操作(例如sns:*
)。为什么我的Cognito用户被拒绝访问?我的主题策略已设置为只有主题所有者才能订阅...但主题所有者似乎与我的Cognito用户相同。
很高兴听到你的工作。一如果你有任何问题,随时张贴在这里或在我们的论坛。 –
另一个注意事项:你不能只复制/粘贴上面,它将无法验证。不应该给予完全访问权限。最简单的方法是使用策略生成器并选择SNS和订阅。超级简单。 – user3344977